public async Task <IActionResult> Create([Bind("id,startDate,endDate,appicationDate,approved")] HospitalLeaveModel HospitalLeaveModel, IFormFile abCard) { if (await extractUser()) { ModelState.Remove("applicant"); ModelState.Remove("ambulatoryCard"); if (ModelState.IsValid && HospitalLeaveModel.startDate >= DateTime.Now && HospitalLeaveModel.startDate <= HospitalLeaveModel.endDate && abCard != null) { using (var ms = new MemoryStream()) { abCard.CopyTo(ms); HospitalLeaveModel.ambulatoryCard = ms.ToArray(); } HospitalLeaveModel.applicant = user; _context.Add(HospitalLeaveModel); await _context.SaveChangesAsync(); return(RedirectToAction("IndexDisapproved")); } return(View("~/Views/Holidays/HolidaysHospitalCRUD/Create.cshtml", HospitalLeaveModel)); } else { return(RedirectToAction("Index", "LogIn")); } }
public async Task <IActionResult> Create([Bind("id,name,description")] ProjectModel projectModel) { if (await extractUser()) { if (ModelState.IsValid) { if (user.role.name == "CEO") { _context.Add(projectModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { return(View("NoPermission")); } } else { return(View(projectModel)); } } else { return(RedirectToAction("Index", "LogIn")); } }
public async Task <IActionResult> Index([Bind("username,firstName,lastName,password,confirmPassword")] UserModel userModel) { if (ModelState.IsValid) { //TODO async if (!_context.Users.Select(u => u.username).Contains(userModel.username)) { userModel.role = await _context.Roles.Where(r => r.name == "Unassigned").FirstOrDefaultAsync(); userModel.password = Utilities.HashFunctions.HashPassword(userModel.password); _context.Add(userModel); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "LogIn")); } else { ViewData["Error message"] = "This username is taken!"; return(View()); } } else { ViewData["Error message"] = "One or more field has data that doesn't match the criteria for it!"; return(View()); } }
public async Task <IActionResult> Create([Bind("id,username,firstName,lastName,password")] UserModel userModel) { if (await extractUser()) { if (user.role.name == "CEO") { ModelState.Remove("confirmPassword"); if (ModelState.IsValid) { userModel.role = await _context.Roles.Where(r => r.name == "Unassigned").FirstOrDefaultAsync(); userModel.password = Utilities.HashFunctions.HashPassword(userModel.password); _context.Add(userModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(userModel)); } else { return(View("NoPermission")); } } else { return(RedirectToAction("Index", "LogIn")); } }
public async Task <IActionResult> Create(string teamName) { if (await extractUser()) { if (user.role.name == "CEO") { //TODO: different method Dictionary <string, string> users = await _context.Users.Include(u => u.role).Where(u => u.role.name == "Team Lead" && u.team == null).ToDictionaryAsync(u => u.username, u => (u.firstName + " " + u.lastName)); List <string> projects = await _context.Projects.Select(p => p.name).ToListAsync(); TeamViewModel twm = new TeamViewModel(users, projects); if (teamName != null) { string project = Request.Form["Projects"]; string teamLead = Request.Form["TeamLeads"]; UserModel leader = await _context.Users.Where(u => u.username == teamLead).FirstOrDefaultAsync(); TeamModel temMod = new TeamModel { name = teamName, }; if (project != null) { temMod.project = await _context.Projects.Where(p => p.name == project).FirstOrDefaultAsync(); } if (teamLead != null) { temMod.teamLeader = await _context.Users.Where(u => u.username == teamLead).FirstOrDefaultAsync(); leader.team = temMod; leader.leadedTeam = temMod; } _context.Add(temMod); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { ViewData["Message"] = "You must chose name of the team!"; return(View(twm)); } } else { return(View("NoPermission")); } } else { return(RedirectToAction("Index", "LogIn")); } }
public async Task <IActionResult> Create([Bind("id,isPaid,startDate,endDate,appicationDate,halfDay,approved")] LeaveModel leaveModel) { if (await extractUser()) { ModelState.Remove("applicant"); if (ModelState.IsValid && leaveModel.startDate >= DateTime.Now && leaveModel.startDate <= leaveModel.endDate) { leaveModel.applicant = user; _context.Add(leaveModel); await _context.SaveChangesAsync(); return(RedirectToAction("IndexDisapproved")); } return(View("~/Views/Holidays/HolidaysPaidUnpaidCRUD/Create.cshtml", leaveModel)); } else { return(RedirectToAction("Index", "LogIn")); } }