public async Task <IActionResult> Edit(int id, [Bind("Id,FullName,Email,EmployeeSkills")] EmployeeModelView employeeModelView) { if (id != employeeModelView.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _db.UpdateFromViewAsync(employeeModelView); } catch (DbUpdateConcurrencyException) { if (_db.GetEmployee(employeeModelView.Id) != null) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(employeeModelView)); }
public IActionResult RestaurantEmployeesShow() { LogRestaurant(); ClaimsPrincipal cp = this.User; var claims = cp.Claims.ToList(); var restId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "RestaurantID").Value); var restaurantEmployees = RestaurantsManager.GetRestauranEmployeesByID(restId); List <EmployeeModelView> viewRestaurantEmployees = new List <EmployeeModelView>(); foreach (RestaurantEmployees remployee in restaurantEmployees) { if (remployee.NewRequestFlag != true) { var employeeUser = UsersManager.GetUserByUserId(remployee.Employee.UserId); string fullName = $"{employeeUser.FirstName} {employeeUser.LastName}"; var viewEmployee = new EmployeeModelView { RestaurantId = remployee.RestaurantId, EmployeeId = remployee.EmployeeId, UserId = employeeUser.UserId, EmployeeFullName = fullName, Active = remployee.Active, Status = remployee.Status, StartDate = (DateTime)remployee.StartDate, EndDate = remployee.EndDate, RequestFlag = remployee.NewRequestFlag, RequestStatus = remployee.RequestStatus }; viewRestaurantEmployees.Add(viewEmployee); } } ViewBag.RestaurantID = restId; return(View(viewRestaurantEmployees)); }
public bool AddOrEditSuccessful(EmployeeModelView model) { bool result; using (var client = new HttpClient()) { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, Encoding.UTF8, "application/json"); //client.BaseAddress = new Uri(ConfigurationManager.AppSettings["ApiRoute"].ToString()); client.BaseAddress = new Uri("https://localhost:44313/api/"); var responseTask = client.PostAsync("EmployeeAPI/", data); responseTask.Wait(); var R = responseTask.Result; if (R.IsSuccessStatusCode) { //var readTask = result.Content.ReadAsAsync<IList<PersonAPI0001ViewMode>>(); var readTask = R.Content.ReadAsStringAsync(); readTask.Wait(); result = bool.Parse(readTask.Result); } else //web api sent error response { result = false; //ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } } return(result); }
///<summary>Extracts data from the form, /// saves new inserted skills to skills table, /// and inserts employee skills to database</summary> ///<returns>Returns Employee after modifications /// to be added to or updated in the database</returns> private Employee ExtractData(EmployeeModelView employee) { string cleanedString = employee.EmployeeSkills ?? ""; string[] inputSkills = cleanedString.Split(','); foreach (string inputSkill in inputSkills) { Skill skill = skillServices.GetByName(inputSkill); if (skill == null) { skill = new Skill { Name = inputSkill }; skillServices.Add(skill); } EmployeeSkill employeeSkill = employeeSkillServices .GetById(new Tuple <int, int>(employee.Id, skill.Id)); if (employeeSkill == null) { employeeSkill = new EmployeeSkill(); employeeSkill.EmployeeId = employee.Id; employeeSkill.SkillId = skill.Id; employee.EmployeesSkills.Add(employeeSkill); skill.EmployeesSkills.Add(employeeSkill); employeeSkillServices.Add(employeeSkill); } } return(employee); }
///<summary>Adds new employee to database, /// saves new inserted skills to skills table, /// and inserts employee skills to database asynchronously</summary> public async Task AddViewDataAsync(EmployeeModelView employeeModelView) { Employee employee = ExtractData(employeeModelView); employeeServices.Add(employee); await employeeServices.SaveAsync(); }
public ActionResult AddOrEdit(string Emp_ID, string type = null) { //publisher List <SelectListItem> items = new List <SelectListItem>(); PublisherList(items); var model = new EmployeeModelView(); model.PublisherItems = items; if (string.IsNullOrEmpty(Emp_ID)) { model.EmployeeList = new EmployeeModel(); Session["Type"] = "A"; } else { DynamicParameters dynamicParameters = new DynamicParameters(); dynamicParameters.Add("@EmployeeID", Emp_ID); //return View(DapperORM.ReturnList<EmployeeModel>("EmployeeViewByEmpID", dynamicParameters).FirstOrDefault<EmployeeModel>()); model.EmployeeList = DapperORM.ReturnList <EmployeeModel>("EmployeeViewByEmpID", dynamicParameters).FirstOrDefault <EmployeeModel>(); Session["Type"] = "U"; } if (!string.IsNullOrEmpty(type)) { Session["Type"] = "V"; } return(View(model)); }
public async Task <IViewComponentResult> InvokeAsync(int id) { var restaurantEmployees = RestaurantsManager.GetRestauranEmployeesByID(id); List <EmployeeModelView> viewRestaurantEmployees = new List <EmployeeModelView>(); foreach (RestaurantEmployees remployee in restaurantEmployees) { if (remployee.NewRequestFlag == true) { var employeeUser = UsersManager.GetUserByUserId(remployee.Employee.UserId); string fullName = $"{employeeUser.FirstName} {employeeUser.LastName}"; var viewEmployee = new EmployeeModelView { RestaurantId = remployee.RestaurantId, EmployeeId = remployee.EmployeeId, UserId = employeeUser.UserId, EmployeeFullName = fullName, Active = remployee.Active, Status = remployee.Status, StartDate = (DateTime)remployee.StartDate, EndDate = remployee.EndDate, RequestFlag = remployee.NewRequestFlag, RequestStatus = remployee.RequestStatus }; viewRestaurantEmployees.Add(viewEmployee); } } return(View(viewRestaurantEmployees)); }
///<returns>Returns new created EmployeeModelView after ///filling all view required data</returns> public EmployeeModelView GetNewModelView() { EmployeeModelView emv = new EmployeeModelView(); emv.SuggestedSkills = skillServices.GetAllAsArrayString(); emv.Employees = employeeServices.GetList(e => true).ToList(); return(emv); }
///<summary>Updates employee's data, /// saves new inserted skills to skills table asynchronously</summary> public async Task UpdateFromViewAsync(EmployeeModelView employeeModelView) { await employeeSkillServices.DeleteSkillsAsync(employeeModelView.Id); Employee employee = ExtractData(employeeModelView); employeeServices.Update(employee); await employeeServices.SaveAsync(); }
public async Task <IActionResult> Create([Bind("Id,FullName,Email,EmployeeSkills")] EmployeeModelView employeeModelView) { if (ModelState.IsValid) { await _db.AddViewDataAsync(employeeModelView); return(RedirectToAction(nameof(Index))); } return(View(employeeModelView)); }
///<returns>Returns EmployeeModelView after filling all view required data</returns> public EmployeeModelView GetModelView(int employeeId) { EmployeeModelView emv = employeeServices.GetAsModelView(employeeId); emv.SetEmployeeSkills( employeeSkillServices.GetSkillsNames(employeeId) ); emv.Employees = employeeServices.GetList(e => true).ToList(); emv.SuggestedSkills = skillServices.GetAllAsArrayString(); return(emv); }
//Edit Employee's Edit public IActionResult EmployeeEdit(int id) { LogRestaurant(); string role; ClaimsPrincipal cp = this.User; var claims = cp.Claims.ToList(); var restId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "RestaurantID").Value); var restaurantEmployee = RestaurantsManager.RestaurantByEmployeeId(restId, id); var userId = EmployeesManager.GetUserIdByEmployeeId(restaurantEmployee.EmployeeId); var authId = UsersManager.GetAuthIdByUserId(userId); var authMatrix = UsersManager.GetAuthenticationMatrixByIDs(restId, authId); if (authMatrix != null) { role = authMatrix.Role; } else { role = ""; } var employeeUser = UsersManager.GetUserByUserId(userId); string fullName = $"{employeeUser.FirstName} {employeeUser.LastName}"; var viewEmployee = new EmployeeModelView { RestaurantId = restaurantEmployee.RestaurantId, EmployeeId = restaurantEmployee.EmployeeId, UserId = employeeUser.UserId, EmployeeFullName = fullName, Active = restaurantEmployee.Active, Status = restaurantEmployee.Status, StartDate = (DateTime)restaurantEmployee.StartDate, EndDate = restaurantEmployee.EndDate, RequestFlag = restaurantEmployee.NewRequestFlag, RequestStatus = restaurantEmployee.RequestStatus, Role = role }; ViewBag.EmployeeStatus = GetEmployeeStatus(); ViewBag.EmployeeRole = GetRestaurantRoles(); ViewBag.EmployeeStatusV = GetEmployeeStatusText(restaurantEmployee.Status); if (GetRestaurantRolesValue(role) == "") { ViewBag.EmplyeeRoleV = "0"; } else { ViewBag.EmplyeeRoleV = GetRestaurantRolesText(role); } return(View(viewEmployee)); }
public ActionResult AddOrEdit(EmployeeModelView model) { List <SelectListItem> items = new List <SelectListItem>(); PublisherList(items); model.PublisherItems = items; if (InfoNoError(model)) { if (Emp_idIsExist(model.EmployeeList.Emp_ID) && Session["Type"] == "A") { model.EmployeeList.Emp_ID = string.Empty; TempData["message"] = "Employee ID 已存在,請更換!"; ModelState.Clear(); return(View(model)); } else { if (AddOrEditSuccessful(model)) { if (Session["Type"] == "A") { TempData["message"] = "新增成功!"; } else { TempData["message"] = "更新成功!"; } return(RedirectToAction("Index", "Employee")); } else { model.EmployeeList.Emp_ID = string.Empty; TempData["message"] = "Error!"; ModelState.Clear(); return(View(model)); } } } else { TempData["message"] = "尚有欄位未填寫、日期格有誤、Age或Salary為零!"; return(View(model)); } }
// GET: Employee/Edit/5 public IActionResult Edit(int?id) { if (id == null) { return(View("Index", _db.GetNewModelView())); } EmployeeModelView employeeModelView = _db.GetModelView(id.Value); if (employeeModelView == null) { return(NotFound()); } return(View("Index", employeeModelView)); }
public bool InfoNoError(EmployeeModelView method) { bool result; DateTime dateTime; if (string.IsNullOrEmpty(method.EmployeeList.Emp_ID)) { result = false; } else if (string.IsNullOrEmpty(method.EmployeeList.FName)) { result = false; } else if (string.IsNullOrEmpty(method.EmployeeList.LName)) { result = false; } else if (method.EmployeeList.Age == 0) { result = false; } else if (!DateTime.TryParse(method.EmployeeList.BirthDay.ToString(), out dateTime)) { result = false; } else if (!DateTime.TryParse(method.EmployeeList.Hire_date.ToString(), out dateTime)) { result = false; } else if (string.IsNullOrEmpty(method.EmployeeList.Address)) { result = false; } else if (method.EmployeeList.salary == 0) { result = false; } else { result = true; } return(result); }
// POST: api/EmployeeAPI public bool Post(EmployeeModelView model) { DynamicParameters dynamicParameters = new DynamicParameters(); dynamicParameters.Add("@Emp_id", model.EmployeeList.Emp_ID); dynamicParameters.Add("@FName", model.EmployeeList.FName); dynamicParameters.Add("@LName", model.EmployeeList.LName); dynamicParameters.Add("@hire_date", model.EmployeeList.Hire_date); dynamicParameters.Add("@salary", model.EmployeeList.salary); dynamicParameters.Add("@Age", model.EmployeeList.Age); dynamicParameters.Add("@BirthDay", model.EmployeeList.BirthDay); dynamicParameters.Add("@Address", model.EmployeeList.Address); dynamicParameters.Add("@pub_id", model.EmployeeList.pub_id); dynamicParameters.Add("@foo", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue); DapperORM.ExecuteWithoutReturn("EmployeeAddOrEdit", dynamicParameters); int result = dynamicParameters.Get <int>("@foo"); return(result == 1 ? true : false); }
public IActionResult EmployeeDetails(int id) { LogRestaurant(); int restId = id; ClaimsPrincipal cp = this.User; var claims = cp.Claims.ToList(); var empId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "EmployeeID").Value); var employeeRestaurant = RestaurantsManager.RestaurantByEmployeeId(restId, empId); var viewEmployeeRestaurant = new EmployeeModelView { Restaurant = employeeRestaurant.Restaurant.RestaurantName, RestaurantId = employeeRestaurant.RestaurantId, EmployeeId = employeeRestaurant.EmployeeId, Status = employeeRestaurant.Status, StartDate = (DateTime)employeeRestaurant.StartDate, EndDate = employeeRestaurant.EndDate, Active = employeeRestaurant.Active, RequestFlag = employeeRestaurant.NewRequestFlag, RequestStatus = employeeRestaurant.RequestStatus }; return(View(viewEmployeeRestaurant)); }
public IActionResult EmployeeEdit(EmployeeModelView viewEmployee) { LogRestaurant(); string role; var userId = EmployeesManager.GetUserIdByEmployeeId(viewEmployee.EmployeeId); var authId = UsersManager.GetAuthIdByUserId(userId); var restaurantEmployee = RestaurantsManager.RestaurantByEmployeeId(viewEmployee.RestaurantId, viewEmployee.EmployeeId); var authMatrix = UsersManager.GetAuthenticationMatrixByIDs(viewEmployee.RestaurantId, authId); viewEmployee.Status = GetEmployeeStatusValue(viewEmployee.Status); viewEmployee.Role = GetRestaurantRolesValue(viewEmployee.Role); if (restaurantEmployee.Active == false && viewEmployee.Active == true) { if (viewEmployee.Status == "Employee") { restaurantEmployee.RequestStatus = "Approved"; viewEmployee.EndDate = null; if (authMatrix != null) { if (viewEmployee.Role == null) { authMatrix.Role = "Employee"; } else { authMatrix.Role = viewEmployee.Role; } UsersManager.UpdateAuthenticationMatrixByIDs(authMatrix); } else { if (viewEmployee.Role == null) { role = "Employee"; } else { role = viewEmployee.Role; } var newAuthMatrix = new AuthenticationMatrix { AuthenticationId = authId, RestaurantId = viewEmployee.RestaurantId, Role = role }; UsersManager.AddEmployeeToAutheticationMatrix(newAuthMatrix); } } } else { if (restaurantEmployee.Active == true && viewEmployee.Active == false) { if (viewEmployee.Status == "Employee" || viewEmployee.Status == "Employee on Leave") { if (authMatrix == null) { var newAuthMatrix = new AuthenticationMatrix { AuthenticationId = authId, RestaurantId = viewEmployee.RestaurantId, }; } authMatrix.Role = "Employee on Leave"; UsersManager.UpdateAuthenticationMatrixByIDs(authMatrix); } else { if (authMatrix != null) { UsersManager.DeleteAuthMatrixByIds(viewEmployee.RestaurantId, authId); } } } else { if (viewEmployee.Status != "Employee") { if (authMatrix != null) { UsersManager.DeleteAuthMatrixByIds(viewEmployee.RestaurantId, authId); } } else { if (authMatrix == null) { var newAuthMatrix = new AuthenticationMatrix { AuthenticationId = authId, RestaurantId = viewEmployee.RestaurantId, }; } authMatrix.Role = viewEmployee.Role; UsersManager.UpdateAuthenticationMatrixByIDs(authMatrix); } } } restaurantEmployee.Status = viewEmployee.Status; restaurantEmployee.EndDate = viewEmployee.EndDate; restaurantEmployee.Active = viewEmployee.Active; RestaurantsManager.UpdateRestaurantEmployee(restaurantEmployee); return(RedirectToAction("RestaurantEmployeesShow")); }
public IActionResult EmployeeApply(EmployeeModelView viewEmployee) { LogRestaurant(); bool newEmployee = false; ClaimsPrincipal cp = this.User; var claims = cp.Claims.ToList(); var userId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "UserID").Value); var empId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "EmployeeID").Value); if (empId == 0) { var employee = new Employees { UserId = userId }; EmployeesManager.CreateEmployee(employee); empId = EmployeesManager.GetEmployeeIdByUserId(userId); newEmployee = true; } var restaurants = RestaurantsManager.RestaurantsByEmployeeId(empId); bool newRestaurant = true; bool requestFlag = true; string status; string request; foreach (RestaurantEmployees rest in restaurants) { if (viewEmployee.RestaurantId == rest.RestaurantId) { newRestaurant = false; status = rest.Status; request = rest.RequestStatus; requestFlag = (bool)rest.NewRequestFlag; } } if (newRestaurant) { var restaurantEmployee = new RestaurantEmployees { EmployeeId = empId, RestaurantId = viewEmployee.RestaurantId, RequestStatus = "on Hold", NewRequestFlag = true, Status = "Applicant", Active = false, }; RestaurantsManager.AddEmployeeToRestaurant(restaurantEmployee); if (newEmployee) { TempData["Message"] = "You successfully applied for a position in a Restaurant. You need to Login again to upgrade your new credential!!"; TempData["ErrorMessage"] = null; return(RedirectToAction("Logout", "Account")); } else { TempData["Message"] = "You successfully applied for a position in a Restaurant!!"; TempData["ErrorMessage"] = null; return(RedirectToAction("Profile", "Account")); } } else { TempData["Message"] = null; TempData["ErrorMessage"] = "Sorry!! Your already applied to the Restaurant's position"; return(RedirectToAction("Profile", "Account")); } }