public async Task <ActionResult> AddStaff(AddStaffViewModel viewModel) { if (ModelState.IsValid) { using (REMSDAL dal = new REMSDAL()) { StaffMember staff = new StaffMember(); staff.FirstName = viewModel.FirstName; staff.LastName = viewModel.LastName; dal.StaffMembers.Add(staff); var result = await dal.SaveChangesAsync(); if (result > 0) { viewModel.ActionStatusMessageViewModel.StatusMessage = "Staff Member " + viewModel.FirstName + " " + viewModel.LastName + " added."; viewModel.FirstName = ""; viewModel.LastName = ""; return(View(viewModel)); } } } // If we got this far, something failed, redisplay form viewModel.ActionStatusMessageViewModel.StatusMessage = "There was an issue processing your request."; viewModel.FirstName = ""; viewModel.LastName = ""; return(View(viewModel)); }
public ActionResult PostStaff(AddStaffViewModel staffModel) { if (!ModelState.IsValid) { return(View("AddStaff", staffModel)); } var staffEntry = new { StaffFirstName = staffModel.Staff.FirstName, StaffLastName = staffModel.Staff.LastName, StaffContactNum = staffModel.Staff.ContactNumber, StaffContactEmail = staffModel.Staff.ContactEmail, StaffUserName = staffModel.Staff.Username, StaffPassword = staffModel.Staff.StaffPassword, RoleType = staffModel.Staff.RoleType }; var staffAsJson = JsonConvert.SerializeObject(staffEntry); var response = HttpHelper.Post(staffAsJson, "api/Staff"); Thread.Sleep(1000); return(RedirectToAction("StaffList", "Staff")); }
public AddStaffWindow() { InitializeComponent(); var addStaffViewModel = new AddStaffViewModel(); addStaffViewModel.CloseWindow = new Action(Close); DataContext = addStaffViewModel; }
public AddStaffView(StaffModel model, HomeViewModel home_view_model) { InitializeComponent(); this.AddStaffViewModel = new AddStaffViewModel(model, this, home_view_model); this.DataContext = AddStaffViewModel; this.Owner = Application.Current.MainWindow; first_name_text_box.Focus(); CoreApp.logger.log("AddStaffView successfully initialized!"); }
public ActionResult AddStaff() { AddStaffViewModel viewModel = new AddStaffViewModel(); viewModel.FirstName = ""; viewModel.LastName = ""; return(View(viewModel)); }
public ActionResult AddStaff() { var roleTypes = HttpHelper.GetList <string>("api/roletypes"); var addStaffVm = new AddStaffViewModel() { RoleTypes = roleTypes.Result.ToList(), Staff = new Staff() }; return(View(addStaffVm)); }
/// <summary> /// Action to edit staff details /// </summary> /// <param name="id">Unique id of the staff.</param> /// <param name="t">Type of Staff</param> /// <returns>View showing staff details</returns> public ActionResult EditStaff(int id, StaffTypes t) { try { ViewBag.StaffId = id; HttpCookie conString = Request.Cookies.Get("rwxgqlb"); AddStaffViewModel asvm; if (t == StaffTypes.NonTeaching) { NonTeachingStaff s = new NonTeachingStaff(id, Cryptography.Decrypt(conString.Value)); asvm = new AddStaffViewModel { Address = s.Address, CNIC = s.CNIC, Gender = s.Gender, JobType = s.JobType, Salary = s.Salary, MCompanyCode = s.PhoneNumber.CompanyCode, MCountryCode = s.PhoneNumber.CountryCode, MNumber = s.PhoneNumber.Number, Name = s.Name, StaffType = t }; } else if (t == StaffTypes.Teacher) { Teacher s = new Teacher(id, Cryptography.Decrypt(conString.Value)); asvm = new AddStaffViewModel { Address = s.Address, CNIC = s.CNIC, Gender = s.Gender, Salary = s.Salary, MCompanyCode = s.PhoneNumber.CompanyCode, MCountryCode = s.PhoneNumber.CountryCode, MNumber = s.PhoneNumber.Number, Name = s.Name, StaffType = t }; } else { asvm = null; } return(View(asvm)); } catch (Exception ex) { return(Content(ex.Message)); } }
public IActionResult Add(AddStaffViewModel addStaffViewModel) { if (ModelState.IsValid) { Staff newStaff = new Staff { Name = addStaffViewModel.Name, Skill = addStaffViewModel.Job, Wage = addStaffViewModel.Wage }; context.Add(newStaff); context.SaveChanges(); return(Redirect("/Staff/ViewStaff/" + newStaff.ID)); } return(View(addStaffViewModel)); }
public IActionResult AddStaff(long id, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; var viewModel = new AddStaffViewModel(); var company = _context.CompanyDetails.SingleOrDefault(c => c.Id == id); var customer = new Customer() { Company = company }; viewModel.Customer = customer; viewModel.Titles = Title.GetTitles(_context.Titles.Where(c => c.Id > 0).OrderBy(x => x.Value).ToList()); return(View(viewModel)); }
public AddStaffView(StaffListViewModel staffListViewModel, EmployeeService employeeService, WardService wardService, WorkUnitService workUnitService, SpecialtyService specialtyService, JobClassService jobClassService, EmployeeSpecialtyService employeeSpecialtyService, WardEmployeeService wardEmployeeService, UnitEmployeeService unitEmployeeService) { _toAddStaff = new AddStaffViewModel(staffListViewModel, employeeService, wardService, workUnitService, specialtyService, jobClassService, employeeSpecialtyService, wardEmployeeService, unitEmployeeService); DataContext = _toAddStaff; InitializeComponent(); }
public async Task <IActionResult> AddStaff(AddStaffViewModel model) { if (ModelState.IsValid) { using (var client = _restClient.CreateClient(User)) { using ( var response = await client.PostAsync("/api/auth/AddStaff", new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"))) { if (response.StatusCode == HttpStatusCode.Created) { return(RedirectToAction("Index")); } } } } ModelState.AddModelError("AddFail", "Add Staff failed please refresh page"); return(View(model)); }
public IActionResult AddStaff(AddStaffViewModel model) { if (ModelState.IsValid) { Debug.Assert(model.StaffType != null, "model.StaffType != null"); var error = _staffService.AddStaff(new AddStaffRequest { Password = model.Password, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, StaffType = model.StaffType.Value, PhoneNumber = model.PhoneNumber, Address = model.Address }); switch (error) { case null: return(RedirectToAction("Index")); case ResponseErrorEnum.EmailAlreadyUsed: ModelState.AddModelError(nameof(model.Email), "This email is already used."); break; default: return(this.InternalServerError()); } } var indexModel = new AdminViewModel(); FillAdminViewModel(indexModel); indexModel.AddStaffViewModel = model; indexModel.OpenAddStaffModal = true; return(View("Index", indexModel)); }
public ActionResult EditStaff(AddStaffViewModel model, int id) { try { HttpCookie conString = Request.Cookies.Get("rwxgqlb"); //getting the encrypted connection string from cookies if (!ModelState.IsValid) { //f the model state is not acorrding to the given format ViewBag.StaffId = id; //sending the staff id back to the view for again processing ViewBag.StaffType = model.StaffType; //sending staff type to the view via viewbag return(View()); } if (model.StaffType == StaffTypes.NonTeaching && model.JobType == null) { //if the staff type is non-teaching & job type is not selected ModelState.AddModelError("JobType", "This field is required"); //adding error meesage ViewBag.StaffId = id; //sending the staff id back to the view for again processing ViewBag.StaffType = model.StaffType; //sending staff type to the view via viewbag return(View()); } try { if (model.StaffType == StaffTypes.NonTeaching) { //if non-teachng staff is selected NonTeachingStaff s = new NonTeachingStaff(id, Cryptography.Decrypt(conString.Value)) { Address = model.Address, CNIC = model.CNIC, JobType = model.JobType, Name = model.Name, PhoneNumber = new MobileNumber(model.MCountryCode, model.MCompanyCode, model.MNumber), Salary = model.Salary }; } else if (model.StaffType == StaffTypes.Teacher) { //if teaching staff is selected Teacher s = new Teacher(id, Cryptography.Decrypt(conString.Value)) { Address = model.Address, CNIC = model.CNIC, Name = model.Name, PhoneNumber = new MobileNumber(model.MCountryCode, model.MCompanyCode, model.MNumber), Salary = model.Salary }; } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } if (model.StaffType == StaffTypes.Teacher) { return(RedirectToAction("ViewTeacherDetails", new { id = id, s = true })); } else { return(RedirectToAction("ViewNonStaffDetails", new { id = id, s = true })); } } catch (Exception ex) { return(Content(ex.Message)); } }
public ActionResult AddStaff(AddStaffViewModel model) { try { HttpCookie conString = Request.Cookies.Get("rwxgqlb"); //getting the connection string from cookies if (!ModelState.IsValid) { return(View()); } if (model.StaffType == StaffTypes.NonTeaching && model.JobType == null) { ModelState.AddModelError("JobType", "This field is required"); //adding model error which displayed on invalid entry return(View()); } NonTeachingStaff nts = null; Teacher t = null; try { if (model.StaffType == StaffTypes.NonTeaching) { nts = new NonTeachingStaff(model.Name, model.CNIC, model.Address, new Models.HelperModels.MobileNumber(model.MCountryCode, model.MCompanyCode, model.MNumber), model.Salary, model.Gender, model.JobType, Cryptography.Decrypt(conString.Value)); } else if (model.StaffType == StaffTypes.Teacher) { t = new Teacher(model.Name, model.CNIC, model.Address, new Models.HelperModels.MobileNumber(model.MCountryCode, model.MCompanyCode, model.MNumber), model.Salary, model.Gender, Cryptography.Decrypt(conString.Value)); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View()); } if (model.StaffType == StaffTypes.Teacher && t != null) { ViewTeacherDetailsViewModel vtdvm = new ViewTeacherDetailsViewModel { Address = t.Address, CNIC = t.CNIC, Gender = t.Gender + "", Id = t.StaffId, MNumber = t.PhoneNumber.GetLocalViewFormat(), Name = t.Name, Qualifications = new List <TeacherQualification>(), Salary = decimal.Round(t.Salary), Sections = new List <TeacherSection>(), JoiningDate = t.Joiningdate.ToLongDateString() }; foreach (var item in t.Qualifications) { vtdvm.Qualifications.Add(new TeacherQualification { Degree = item.Degree, Id = item.Id, Year = item.Year.ToString(), TeacherId = t.StaffId }); } foreach (var item in t.GetAssignedSections()) { vtdvm.Sections.Add(new TeacherSection { Class = item.Section.Class.Name, Section = item.Section.Name, SectionId = item.Section.SectionId, Subject = item.Subject.Name, SubjectId = item.Subject.SubjectId, TeacherId = t.StaffId }); } ViewBag.Success = true; return(View("ViewTeacherDetails", vtdvm)); } else if (model.StaffType == StaffTypes.NonTeaching && nts != null) { ViewNonStaffDetailsViewModel vnvm = new ViewNonStaffDetailsViewModel { Address = nts.Address, CNIC = nts.CNIC, Gender = nts.Gender + "", Id = nts.StaffId, JobType = nts.JobType, MNumber = nts.PhoneNumber.GetLocalViewFormat(), Name = nts.Name, Salary = decimal.Round(nts.Salary), JoiningDate = nts.Joiningdate.ToLongDateString() }; ViewBag.Success = true; return(View("ViewNonStaffDetails", vnvm)); } else { return(View()); } } catch (Exception ex) { return(Content(ex.Message)); } }
public IActionResult Add() { AddStaffViewModel addStaffViewModel = new AddStaffViewModel(); return(View(addStaffViewModel)); }
public async Task <IActionResult> AddStaff(AddStaffViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Username, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _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); // create additional user info var contact = new UserContact(); var newUser = new UserDetail(); contact.BuildingNumber = model.BuildingNumber; contact.AddressLine1 = model.AddressLine1; contact.AddressLine2 = model.AddressLine2; contact.PostTown = model.PostTown; contact.County = model.County; contact.Country = model.Country; contact.Postcode = model.Postcode; contact.MobilePhone = model.MobilePhone; contact.WorkPhone = model.WorkPhone; contact.OtherPhone = model.OtherPhone; contact.Email = model.Email; contact.UserId = user.Id; _context.Add(contact); _context.SaveChanges(); newUser.ForeName = model.ForeName; newUser.Surname = model.Surname; newUser.Name = model.ForeName + ' ' + model.Surname; newUser.Title = model.Title; newUser.StartDate = DateTime.Now; newUser.EndDate = new DateTime(2070, 1, 1); newUser.UserContactId = contact.Id; newUser.CompanyId = model.Customer.Company.Id; newUser.UserId = user.Id; _context.Add(newUser); _context.SaveChanges(); // Create welcome message _context.Add(Messages.WelcomeMessage(user.Id, newUser.Name)); _context.SaveChanges(); // Add CanViewCompany role await _userManager.AddToRoleAsync(user, "CanViewCompany"); return(RedirectToLocal("/Customer/StaffDetail/" + newUser.Id)); } AddErrors(result); } // If we got this far, something failed, redisplay form model.Titles = Title.GetTitles(_context.Titles.Where(c => c.Id > 0).OrderBy(x => x.Value).ToList()); return(View(model)); }