Exemple #1
0
        public ActionResult CityUsers(string CityId, string[] Users)
        {
            Response res = new Response();

            foreach (var city in CityId.Split(','))
            {
                try
                {
                    DataTable Data = new DataTable();
                    Data.Columns.AddRange(new DataColumn[2]
                    {
                        new DataColumn("Id", typeof(int)),
                        new DataColumn("value", typeof(string))
                    });


                    foreach (var item in Users)
                    {
                        DataRow row;
                        row          = Data.NewRow();
                        row["Id"]    = Convert.ToInt32(city);
                        row["value"] = item;

                        Data.Rows.Add(row);
                    }

                    UserCityDL uctd = new UserCityDL();
                    uctd.Insert("CityUsers", Convert.ToInt32(city), Data);

                    res.Status  = "success";
                    res.Message = "save successfully";
                }
                catch (Exception ex)
                {
                    res.Status  = "danger";
                    res.Message = ex.Message;
                }
            }

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public bool ByUser(int UserId, string[] PermissionIds, string[] Clients, string[] cities, int[] Scopes, int[] Projects, int[] DefinationType)
        {
            try
            {
                DataTable Data = new DataTable();
                Data.Columns.AddRange(new DataColumn[2]
                {
                    new DataColumn("Id", typeof(int)),
                    new DataColumn("value", typeof(string))
                });


                if (PermissionIds != null)
                {
                    foreach (var item in PermissionIds)
                    {
                        DataRow row;
                        row          = Data.NewRow();
                        row["Id"]    = UserId;
                        row["value"] = item;

                        Data.Rows.Add(row);
                    }
                }

                UserPermissionDL rpd = new UserPermissionDL();
                if (rpd.Insert(UserId, Data))
                {
                    // for save user Clints
                    Data.Rows.Clear();

                    if (Clients != null && Clients.Length > 0)
                    {
                        foreach (var item in Clients)
                        {
                            DataRow row;
                            row          = Data.NewRow();
                            row["Id"]    = UserId;
                            row["value"] = item;

                            Data.Rows.Add(row);
                        }

                        UserClientsDL ucd = new UserClientsDL();
                        ucd.Insert(UserId, Data);
                    }


                    // for save user Cities

                    Data.Rows.Clear();

                    if (cities != null && cities.Length > 0)
                    {
                        var CityIds = cities.Where(m => m.Contains("r-")).ToArray();
                        foreach (var item in cities)
                        {
                            DataRow row;
                            row       = Data.NewRow();
                            row["Id"] = UserId;
                            if (item.Contains("r-"))
                            {
                                row["value"] = item.Remove(0, 2);
                            }
                            else
                            {
                                row["value"] = item.Remove(0, 4);
                            }


                            Data.Rows.Add(row);
                        }

                        UserCityDL uctd = new UserCityDL();
                        uctd.Insert("UserCities", UserId, Data);
                    }



                    if (Scopes != null && Scopes.Length > 0)
                    {
                        Data.Rows.Clear();
                        foreach (var item in Scopes)
                        {
                            DataRow row;
                            row          = Data.NewRow();
                            row["Id"]    = UserId;
                            row["value"] = item;

                            Data.Rows.Add(row);
                        }

                        Sec_UserScopeDL usd = new Sec_UserScopeDL();
                        usd.Manage(UserId, Data);
                    }


                    if (DefinationType != null && DefinationType.Length > 0)
                    {
                        Data.Rows.Clear();
                        foreach (var item in DefinationType)
                        {
                            DataRow row;
                            row          = Data.NewRow();
                            row["Id"]    = UserId;
                            row["value"] = item;

                            Data.Rows.Add(row);
                        }

                        Sec_UserDL usd = new Sec_UserDL();
                        usd.ManageUserDefinationTypes(UserId, Data);
                    }
                    //Projects
                    if (Projects != null && Projects.Length > 0)
                    {
                        Data.Rows.Clear();
                        foreach (var item in Projects)
                        {
                            DataRow row;
                            row          = Data.NewRow();
                            row["Id"]    = UserId;
                            row["value"] = item;

                            Data.Rows.Add(row);
                        }

                        Sec_UserProjectsDL usd = new Sec_UserProjectsDL();
                        usd.Manage(ViewBag.UserId, Data, UserId, "Insert");
                    }
                    Permission.ChangeUserId(UserId);
                    TempData["msg_success"] = "Save Successfully.";
                }
                return(true);
            }
            catch (Exception ex)
            {
                TempData["msg_error"] = ex.Message;
                return(false);
            }
        }