public ActionResult Apply(AddStatementViewModel model) { if (User.Identity.IsAuthenticated && (User.IsInRole("Admin") || User.IsInRole("User"))) { if (ModelState.IsValid) { if (model.Captcha != Session["code"].ToString()) { ModelState.AddModelError("Captcha", "Неправильно введений код перевірки!"); } if (model.Consent == false) { ModelState.AddModelError("Consent", "Потрібне підтвердження!"); } if (ModelState.IsValid) { StatementManager.ApplyStatement(model, User.Identity.GetUserId()); return(RedirectToAction("Index", "Home")); } List <Kindergarten> Kindergartens = KindergartenManager.GetKindergartens().ToList(); model.Kindergartens = new SelectList(Kindergartens, "Id", "Name"); return(View(model)); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Apply(string id) { if (User.Identity.IsAuthenticated) { List <Privilege> privileges = StatementManager.GetAllPrivileges(); List <Group> groups = StatementManager.GetAllGroups(); List <Kindergarten> Kindergartens = KindergartenManager.GetKindergartens().ToList(); AddStatementViewModel model = new AddStatementViewModel { }; model.Privileges = new List <PrivilegesInnerViewModel> { }; model.Groups = new List <string> { }; for (int i = 0; i < privileges.Count; i++) { model.Privileges.Add(new PrivilegesInnerViewModel { Key = privileges[i].Value, Value = false }); } for (int i = 0; i < groups.Count; i++) { model.Groups.Add(groups[i].Value); } model.Kindergartens = new SelectList(Kindergartens, "Id", "Name"); return(View(model)); } return(RedirectToAction("Index", "Home")); }
public void ApplyStatement(AddStatementViewModel model, string userId) { Statement statement = new Statement { KindergartenId = model.SelectedKindergartenId, SiteUserId = userId, SNF = model.SNF, SeriesNumberPassport = model.SeriesNumberPassport, ChildSNF = model.ChildSNF, ChildDateOfBirth = model.DateOfBirth, ChildBirthCertificate = model.ChildBirthCertificate, Group = model.SelectedGroup, Address = model.Address, Email = model.Email, PhoneNumber = model.PhoneNumber, AdditionalPhoneNumber = model.AdditionalPhoneNumber, Status = "NotConsidered", IsSelected = false, IsRemoved = false, DateTime = DateTime.Now }; db.Statements.Add(statement); string tempKey; for (int i = 0; i < model.Privileges.Count; i++) { if (model.Privileges[i].Value) { tempKey = model.Privileges[i].Key; db.UserPrivilegeStatements.Add(new UserPrivilegeStatement { StatementId = statement.Id, UserPrivilegeId = db.UserPrivileges.Where(up => up.Value == tempKey).First().Id }); } } db.SaveChanges(); }