Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FirstLevel.Models.ObjectGroup;
using FirstLevel.ServiceReference2;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.ServiceModel;
using Valentica.Libraries;

namespace FirstLevel.Controllers
{
    public class RightsController : Controller
    {
        //
        // GET: /Rights/
        Service1Client sc = new Service1Client();
        ObjectGroup ob = new ObjectGroup();
        public ActionResult Index(int? pageid, int? pagesize)
        {
            if (sc.State == CommunicationState.Closed)
            {
                sc.Open();
            }

            List<SelectListItem> rolename = new List<SelectListItem>();
            rolename.Add(new SelectListItem() { Text = "---Select Role---", Value = "0", Selected = true });
            var listR = sc.GetRoleName();
            foreach (var x in listR)
            {
                rolename.Add(new SelectListItem() { Text = x.Rolname, Value = x.Rolid.ToString() });
            }
            ViewData["Rolebind"] = null;
            ViewData["Rolebind"] = rolename;
            var listG = sc.Getobjectdetails();
            sc.Close();
            string dt = "";
            foreach (var r in listG)
            {
                dt += r.ObjectId + "!";
            }
            ob.Objectnos = dt;
            ViewData["Objectgroupdata"] = listG;
           
             return View(ob);
        }
        [HttpPost]
        public ActionResult Index(ObjectGroup og)
        {
            int roleid = 0;
            roleid = og.RoleID;
            sc.Open();
            if (!string.IsNullOrEmpty(og.divdetails))
            {
                string[] arr = og.divdetails.Split('$');
                for (int i = 0; i < arr.Length; i++)
                {
                    if (!string.IsNullOrEmpty(arr[i]))
                    {
                        string[] arr1 = arr[i].Split('!');
                        int objno = Convert.ToInt32(arr1[0]);
                        sc.DeleteExistingRights(objno, roleid);
                        
                        if (arr1[1] == "Y" || arr1[2] == "Y" || arr1[3] == "Y" || arr1[4] == "Y")
                        {
                            CompositeObjectGroup co = new CompositeObjectGroup();
                            co.RoleId = roleid;
                            co.ObjectId = objno;
                            if (arr1[1] == "Y")
                            { co.Delete = true; }
                            else { co.Delete = false; }
                            if (arr1[2] == "Y")
                            { co.All = true; }
                            else { co.All = false; }
                            if (arr1[1] == "Y")
                            { co.Add = true; }
                            else { co.Add = false; }
                            if (arr1[1] == "Y")
                            { co.Edit = true; }
                            else { co.Edit = false; }
                            if (arr1[1] != "Y" && arr1[2] != "Y" && arr1[3] != "Y" && arr1[4] != "Y")
                            {
                                co.All = true;
                            }
                            else
                            {
                                co.All = false;
                            }
                            co.CreatedOn = DateTime.Now.Date;
                            co.createdby  = Convert.ToInt32(Session["UserID"].ToString());
                            sc.AddRightsdata(co);
                        }
                    }
                }
                sc.Close();
            }       
            return RedirectToAction("Index");
        }
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult GetData(int id)
        {
           // RT rht = new RT();
            short rid = (short)Convert.ToInt32(id);
            string dt = "";
            sc.Open();
            var obj = sc.Getobjectdetails().OrderBy(x => x.GroupId);
            var Sub = sc.GetRightslist(rid);
            foreach (var K in obj)
            {
                string flag = "N";
                dt += K.ObjectId + "!";
                foreach (var D in Sub)
                {
                    if (K.ObjectId == D.ObjectId)
                    {
                        dt += D.Delete + "!";
                        dt += D.Edit+ "!";
                        dt += D.Add + "!";
                        dt += D.All + "$";
                        flag = "Y";
                    }
                }
                if (flag == "N")
                {
                    dt += "N!";
                    dt += "N!";
                    dt += "N!";
                    dt += "N$";
                }
            }
            return Json(dt, JsonRequestBehavior.AllowGet);
        }
    }


}
Posted
Updated 6-Sep-13 0:08am
v2
Comments
[no name] 6-Sep-13 6:25am    
The very first thing to do would be to learn how to ask a question.

Hi,

There are some third party tools available in the market. Some are commercial and some are free to use. Although it will not complies all your need. Please find below tools that may help you.

FXCop (Free)
StyleCop (Free)
ReSharper (Paid)

Hope this will help you.

Thanks
-Amit Gajjar
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900