Exemple #1
0
        public IActionResult Create(Guid id)
        {
            var model = new Models.tbls.user.user {
                Roles = new string[0], isActive = true, Id = Guid.NewGuid()
            };
            var x = db.TblUsers.Find(id);

            if (x != null)
            {
                model = new Models.tbls.user.user(x, db);
            }
            return(View(model));
        }
Exemple #2
0
        public IActionResult Create(Models.tbls.user.user model)
        {
            var x = db.TblUsers.Find(model.Id);

            if (x != null)
            {
                ModelState.Remove("Password");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.error = "ثبت انجام نشد";
                return(View(model));
            }
            if (x == null)
            {
                x = new web_db.TblUser {
                    Id = model.Id, IsDel = false, Salmalidef = User._getuserSalMaliDef()
                };
                db.TblUsers.Add(x);
            }
            try
            {
                x.Mob = model.Mob;
                if (model.Password.IsEmpty() == false)
                {
                    x.Password = model.Password;
                }
                x.Roles    = string.Join(',', model.Roles);
                x.Title    = model.Title;
                x.Username = model.Username;
                x.IsActive = model.isActive;

                foreach (var item in model.Permis)
                {
                    var z = db.TblUserPermis.SingleOrDefault(a => a.FkUser == x.Id && a.FkPortageType == item.FkPortageType);
                    if (z == null)
                    {
                        z = new web_db.TblUserPermi {
                            FkPortageType = item.FkPortageType, FkUser = x.Id
                        };
                        db.TblUserPermis.Add(z);
                    }
                    z.IsIn      = item.IsIn;
                    z.IsInBack  = item.IsInBack;
                    z.IsOut     = item.IsOut;
                    z.IsOutBack = item.IsOutBack;
                    z.IsReport  = item.IsReport;
                    z.IsType    = z.IsIn || z.IsInBack || z.IsOut || z.IsOutBack;
                }

                try
                {
                    db.SaveChanges(); ViewBag.txt = "ثبت انجام شد";
                    return(RedirectToAction(nameof(ListUser)));
                }
                catch (Exception e)
                {
                    ViewBag.error = e.Message;
                }
            }
            catch { }
            return(View(model));
        }