public async Task <IActionResult> Create([Bind("OwnersLicenseId,CompanyName,ExpireDate,Active,LicenseEmail")] OwnersLicense ownersLicense) { try { if (ModelState.IsValid) { string flagEmpOrClient = "Employee"; _context.Add(ownersLicense); await _context.SaveChangesAsync(); var licenseEmail = ownersLicense.LicenseEmail; int licenseId = ownersLicense.OwnersLicenseId; var callbackUrl = Url.EmailRegistrationLink(licenseId, licenseEmail, Request.Scheme, flagEmpOrClient); await _emailSender.SendEmailRegistrationAsync(licenseEmail, callbackUrl); TempData["message"] = "The License has been successfully added and the verification email sent."; return(RedirectToAction(nameof(Index))); } } catch (Exception e) { ModelState.AddModelError("", $"Create error:{e.GetBaseException().Message}"); } Create(); return(View(ownersLicense)); }
public async Task <IActionResult> Create([Bind("PersonId,FirstName,LastName,MiddleName,Address,Email,OwnersLicenseId,Address2,ProvinceId,PostalCode,PhoneNumber,PersonImage")] Person person) { if (ModelState.IsValid) { _context.Add(person); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["OwnersLicenseId"] = new SelectList(_context.OwnersLicense, "OwnersLicenseId", "Active", person.OwnersLicenseId); ViewData["ProvinceId"] = new SelectList(_context.Province, "ProvinceId", "ProvinceCode", person.ProvinceId); return(View(person)); }
public async Task <IActionResult> Create([Bind("CountryId,CountryName")] Country country) { try { if (ModelState.IsValid) { _context.Add(country); await _context.SaveChangesAsync(); TempData["message"] = "The Country has been successfully added to the Database."; return(RedirectToAction(nameof(Index))); } } catch (Exception e) { ModelState.AddModelError("", $"Create error:{e.GetBaseException().Message}"); } return(View(country)); }
public async Task <IActionResult> Create([Bind("ProjectId,ClientId,EmployeeId,ProjectOpen,ProjectName,StartDate,EndDate,ProjectDescription")] Project project) { try { if (ModelState.IsValid) { _context.Add(project); await _context.SaveChangesAsync(); TempData["message"] = "The Project has been successfully created."; return(RedirectToAction(nameof(Index))); } } catch (Exception e) { ModelState.AddModelError("", $"Create error:{e.GetBaseException().Message}"); } Create(); return(View(project)); }
public async Task <IActionResult> Create([Bind("TaskListId,TaskListName,ProjectId,TaskListOpen")] TaskList taskList) { if (ModelState.IsValid) { try { _context.Add(taskList); await _context.SaveChangesAsync(); TempData["message"] = "Record successfully created"; return(RedirectToAction(nameof(Index))); } catch (Exception e) { TempData["message"] = $"Create error: {e.GetBaseException().Message}"; } } ViewData["ProjectId"] = new SelectList(_context.Project, "ProjectId", "ProjectDescription", taskList.ProjectId); return(View(taskList)); }
public async Task <IActionResult> Create([Bind("PersonId,FirstName,LastName,MiddleName,Address,Email,OwnersLicenseId,Address2,ProvinceId,PostalCode,PhoneNumber,PersonImage")] Person person) { try { if (ModelState.IsValid) { _context.Add(person); await _context.SaveChangesAsync(); TempData["message"] = "Record Successfully added."; return(RedirectToAction("index", "projects")); } } catch (Exception e) { ModelState.AddModelError("", $"Create error:{e.GetBaseException().Message}"); } Create(); return(View(person)); }
public async Task <IActionResult> Create([Bind("TaskInfoId,TaskId,TaskNote")] TaskInfo taskInfo) { if (ModelState.IsValid) { try { _context.Add(taskInfo); await _context.SaveChangesAsync(); TempData["message"] = "The Record has been successfully added to the Database."; return(RedirectToAction(nameof(Index))); } catch (Exception e) { ModelState.AddModelError("", $"Create error:{e.GetBaseException().Message}"); } } ViewData["TaskId"] = new SelectList(_context.Task, "TaskId", "TaskDescription", taskInfo.TaskId); return(View(taskInfo)); }
public async Task <IActionResult> Create([Bind("OwnersLicenseId,CompanyName,ExpireDate,Active")] OwnersLicense ownersLicense) { try { if (ModelState.IsValid) { _context.Add(ownersLicense); await _context.SaveChangesAsync(); TempData["message"] = "The License has been successfully added"; HttpContext.Session.SetString("ownersLicenseId", ownersLicense.OwnersLicenseId.ToString()); return(RedirectToAction("create", "person")); } } catch (Exception e) { ModelState.AddModelError("", $"Create error:{e.GetBaseException().Message}"); } Create(); return(View(ownersLicense)); }
public async Task <IActionResult> Create([Bind("TaskId,EmployeeId,TaskListId,TaskName,TaskWeight,TaskDescription,ExpectedDate,TaskDuration,TaskActiveFlag")] Models.Task task) { if (ModelState.IsValid) { try { _context.Add(task); await _context.SaveChangesAsync(); TempData["message"] = "The Country has been successfully added to the Database."; return(RedirectToAction(nameof(Index))); } catch (Exception e) { ModelState.AddModelError("", $"Create error:{e.GetBaseException().Message}"); } } ViewData["EmployeeId"] = new SelectList(_context.Employee, "EmployeeId", "EmployeeId"); ViewData["TaskListId"] = new SelectList(_context.TaskList, "TaskListId", "TaskListId"); return(View(task)); }
public async Task <IActionResult> Register(RegisterViewModel model, Client client, Employee employee, Person person, IFormFile PersonImage, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { string flagEmpOrClient = HttpContext.Session.GetString("flagEmpOrClient"); if (flagEmpOrClient == null) { TempData["Message"] = "The system could not identify the new user as a Client or Employee. Please contact admin for details."; return(RedirectToAction("register", "account")); } //The next line adds the person to Db if (PersonImage != null) { using (var stream = new MemoryStream()) { await PersonImage.CopyToAsync(stream); person.PersonImage = stream.ToArray(); person.ImageContentType = PersonImage.ContentType; } } _context.Add(person); if (flagEmpOrClient == "Employee") { //The next block creates a blank employee var personId = person.PersonId; employee.PersonId = personId; employee.EmployeeActiveFlag = 1; _context.Add(employee); } else if (flagEmpOrClient == "Client") { //The next block creates a blank client var personId = person.PersonId; client.PersonId = personId; client.ClientActiveFlag = 1; _context.Add(client); } var licenseId = int.Parse(HttpContext.Session.GetString("licenseId")); var firstPerson = _context.Person.FirstOrDefault(a => a.OwnersLicenseId == licenseId); await _context.SaveChangesAsync(); var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (firstPerson == null) { await _userManager.AddToRoleAsync(user, "Admin"); } else if (flagEmpOrClient == "Employee") { await _userManager.AddToRoleAsync(user, "Employee"); } else { await _userManager.AddToRoleAsync(user, "Client"); } _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } ViewData["OwnersLicenseId"] = new SelectList(_context.OwnersLicense, "OwnersLicenseId", "Active"); ViewData["ProvinceId"] = new SelectList(_context.Province, "ProvinceId", "ProvinceName"); // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Create(int?id) { var modelProject = await _context.ModelProject.Include(a => a.ModelTaskList) //.Include(a => a.ModelTask).Include(a => a.ModelTaskInfo); //.Select(b => b.ModelTask.Select(c => c.ModelTaskInfo))) .SingleOrDefaultAsync(m => m.ModelProjectId == id); //var modelTask = await _context.ModelTaskList.Include(a => a.ModelTask).SingleOrDefaultAsync(m => m.ModelTaskListId == id); //.Include(a => a.ModelTask).Include(a => a.ModelTaskInfo) //new Project var user = _userManager.GetUserName(User); var personId = _context.Person.FirstOrDefault(a => a.Email == user).PersonId; var newProject = new Project { ClientId = 1, EmployeeId = _context.Employee.FirstOrDefault(a => a.PersonId == personId).EmployeeId, ProjectName = modelProject.ModelProjectName, ProjectDescription = modelProject.ModelProjectDescription, ProjectOpen = 1, StartDate = DateTime.Now }; _context.Add(newProject); var projectId = newProject.ProjectId; //New Task List foreach (var itemTaskList in modelProject.ModelTaskList) { var newTaskList = new TaskList { TaskListName = itemTaskList.ModelTaskListName, ProjectId = projectId, TaskListOpen = 1 }; _context.Add(newTaskList); var modelTaskListId = itemTaskList.ModelTaskListId; var modelTasks = await _context.ModelTaskList.Include(b => b.ModelTask).SingleOrDefaultAsync(a => a.ModelTaskListId == modelTaskListId); var taskListId = newTaskList.TaskListId; //New Task foreach (var itemTask in modelTasks.ModelTask) { var totalDate = DateTime.Now.AddHours(Convert.ToDouble(itemTask.ModelTaskDuration)); var newTask = new Models.Task { TaskListId = taskListId, TaskName = itemTask.ModelTaskName, TaskWeight = itemTask.ModelTaskWeight, TaskDescription = itemTask.ModelTaskDescription, ExpectedDate = totalDate, TaskActiveFlag = itemTask.ModelTaskActiveFlag, TaskDuration = itemTask.ModelTaskDuration }; _context.Add(newTask); var modelTaskId = itemTask.ModelTaskId; var modelTaskInfos = await _context.ModelTask.Include(b => b.ModelTaskInfo).SingleOrDefaultAsync(a => a.ModelTaskId == modelTaskId); var taskId = newTask.TaskId; foreach (var itemTaskInfo in modelTaskInfos.ModelTaskInfo) { var newTaskInfo = new TaskInfo { TaskId = taskId, TaskNote = itemTaskInfo.ModelTaskNote }; _context.Add(newTaskInfo); } } } await _context.SaveChangesAsync(); TempData["message"] = "The Project has been successfully loaded."; return(RedirectToAction(nameof(Index))); }