public ActionResult Create(ContractViewModel cvm) { if (ModelState.IsValid) { var selectedZones = new List <GeographicalZone>(); if (cvm.ZonesIds != null) { var zonesFromDbs = zoneRepository.GetByFilter(z => cvm.ZonesIds.Contains(z.Id)); zonesFromDbs.ToList().ForEach(z => selectedZones.Add(z)); } var userZone = (string)Session["zone"]; selectedZones.Add(zoneRepository.GetByFilter(z => z.Label == userZone).FirstOrDefault()); var contract = new Contract { Name = cvm.Contract.Name, InitDate = cvm.Contract.InitDate, EndDate = cvm.Contract.EndDate, Bonus = cvm.Contract.Bonus, Company = cvm.Contract.Company, PortfolioId = cvm.Contract.PortfolioId, Zones = selectedZones }; contractRepository.Insert(contract); contractRepository.SaveChanges(); return(RedirectToAction("Index", "Portfolio/" + contract.PortfolioId)); } return(View()); }
public ActionResult Login(UserViewModel uvm) { if (ModelState.IsValid) { LDAPUser ldapUserDetails = LDAPService.Instance.AuthenticationAndIdentification(uvm.User.Username, uvm.User.Password); if (ldapUserDetails == null) { ModelState.AddModelError(string.Empty, "Wrong username or password."); return(View("Index", uvm)); } var user = userRepository.GetByFilter(u => u.Username == uvm.User.Username).FirstOrDefault(); if (user == null) { var newUser = new User { Firstname = ldapUserDetails.Firstname, Lastname = ldapUserDetails.Lastname, Username = ldapUserDetails.Username, Email = ldapUserDetails.Email, Zone = zoneRepository.GetByFilter(z => z.Label == ldapUserDetails.Zone).FirstOrDefault(), Role = roleRepository.GetByFilter(r => r.RoleName == Roles.COLLABORATOR).FirstOrDefault() }; userRepository.Insert(newUser); userRepository.SaveChanges(); Session["username"] = newUser.Username; Session["role"] = newUser.Role.RoleName.ToString("g"); Session["id"] = newUser.Id; Session["Zone"] = newUser.Zone.Label; } else { user.Role = roleRepository.GetById(user.RoleId); Session["username"] = user.Username; Session["role"] = user.Role.RoleName.ToString("g"); Session["id"] = user.Id; Session["Zone"] = user.Zone.Label; if (this.IsAdmin()) { return(RedirectToAction("Index", "Admin")); } } return(RedirectToAction("Index", "Portfolio")); } return(View()); }