Пример #1
0
        public ActionResult AddAdmins(Admins admin)
        {
            foreach (var ms in ModelState.ToArray())
            {
                if (ms.Key.StartsWith("AdminLims["))
                {
                    ModelState.Remove(ms);
                }
            }

            if (TryUpdateModel(admin, new string[] { "username", "password" }) && ModelState.IsValid)
            {
                admin.Isenable = 1;

                if (admin.AdminLims != null)
                {
                    foreach (AdminLims adminlim in admin.AdminLims.ToArray())
                    {
                        if (adminlim.LimID != 0)
                        {
                            adminlim.AdminLimID = Guid.NewGuid();
                        }
                        else
                        {
                            admin.AdminLims.Remove(adminlim);
                        }
                    }
                }

                adminsService.Create(admin);
                adminsService.SaveChanges();

                return(RedirectToAction("Admins"));
            }
            else
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                ViewBag.Lims = limsService.Get().Where(a => a.ParentID == null).OrderBy(a => a.Sort);
                return(View(admin));
            }
        }