public static void AddEmployeeToAutheticationMatrix(AuthenticationMatrix authMatrix) { var context = new TableReadyContext(); context.AuthenticationMatrix.Add(authMatrix); context.SaveChanges(); }
//Approve Employee's Application public IActionResult EmployeeApprove(int id) { LogRestaurant(); ClaimsPrincipal cp = this.User; var claims = cp.Claims.ToList(); var restId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "RestaurantID").Value); var userId = EmployeesManager.GetUserIdByEmployeeId(id); var authId = UsersManager.GetAuthIdByUserId(userId); var restaurantEmployee = RestaurantsManager.RestaurantByEmployeeId(restId, id); restaurantEmployee.NewRequestFlag = false; restaurantEmployee.Status = "Employee"; restaurantEmployee.RequestStatus = "Approved"; restaurantEmployee.Active = true; RestaurantsManager.UpdateRestaurantEmployee(restaurantEmployee); var authRestaurant = UsersManager.GetAuthenticationMatrixByIDs(restId, authId); if (authRestaurant == null) { var authRest = new AuthenticationMatrix { RestaurantId = restId, AuthenticationId = authId, Role = "Employee" }; UsersManager.AddOwnerToAuthetication(authRest); } else { authRestaurant.Role = "Employee"; UsersManager.UpdateAuthenticationMatrixByIDs(authRestaurant); } return(RedirectToAction("RestaurantEmployeesShow")); }
public static void UpdateAuthenticationMatrixByIDs(AuthenticationMatrix restAuth) { var context = new TableReadyContext(); var originalAuthRestaurant = context.AuthenticationMatrix.SingleOrDefault(p => p.AuthenticationId == restAuth.AuthenticationId && p.RestaurantId == restAuth.RestaurantId); originalAuthRestaurant.Role = restAuth.Role; context.SaveChanges(); }
public IActionResult OwnerEdit(OwnerModelView viewOwner) { LogRestaurant(); var userId = OwnersManager.GetUserIdByOwnerId(viewOwner.OwnerId); var authId = UsersManager.GetAuthIdByUserId(userId); var restaurantOwner = RestaurantsManager.RestaurantByOwnerId(viewOwner.RestaurantId, viewOwner.OwnerId); var authMatrix = UsersManager.GetAuthenticationMatrixByIDs(viewOwner.RestaurantId, authId); viewOwner.Status = GetOwnerStatusValue(viewOwner.Status); if (restaurantOwner.Active == false && viewOwner.Active == true) { if (viewOwner.Status == "Owner" || viewOwner.Status == "Primary Owner") { restaurantOwner.RequestStatus = "Approved"; if (authMatrix != null) { authMatrix.Role = "Owner"; UsersManager.UpdateAuthenticationMatrixByIDs(authMatrix); } else { var newAuthMatrix = new AuthenticationMatrix { AuthenticationId = authId, RestaurantId = viewOwner.RestaurantId, Role = "Owner" }; UsersManager.AddOwnerToAuthetication(newAuthMatrix); } } } else { if (restaurantOwner.Active == true && viewOwner.Active == false) { if (viewOwner.Status == "Owner" || viewOwner.Status == "Primary Owner") { authMatrix.Role = "OwnerLeave"; UsersManager.UpdateAuthenticationMatrixByIDs(authMatrix); } else { UsersManager.DeleteAuthMatrixByIds(viewOwner.RestaurantId, authId); } } } restaurantOwner.Status = viewOwner.Status; restaurantOwner.EndDate = viewOwner.EndDate; restaurantOwner.Active = viewOwner.Active; RestaurantsManager.UpdateRestaurantOwner(restaurantOwner); return(RedirectToAction("RestaurantOwnersShow")); }
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 RestaurantCreate(RestaurantCreateModelView viewRestaurant) { LogRestaurant(); bool newOwner = false; ClaimsPrincipal cp = this.User; var claims = cp.Claims.ToList(); var userId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "UserID").Value); var ownId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "OwnerID").Value); var authId = Convert.ToInt32(claims.SingleOrDefault(p => p.Type == "AuthID").Value); var newRestaurant = RestaurantsManager.GetRestaurantIdByName(viewRestaurant.RestaurantName); if (newRestaurant == 0) { var restaurant = new Restaurants { RestaurantName = viewRestaurant.RestaurantName, }; if (ownId == 0) { var owner = new Owners { UserId = userId }; OwnersManager.CreateOwner(owner); ownId = OwnersManager.GetOwnerIdByUserId(userId); newOwner = true; } int restId = RestaurantsManager.CreateRestaurant(restaurant); var restaurantOwner = new RestaurantOwners { RestaurantId = restId, OwnerId = ownId, Status = "Primary Owner", Active = true, Request = false, RequestStatus = "Accepted", }; RestaurantsManager.AddOwnerToRestaurant(restaurantOwner); var authMatrix = new AuthenticationMatrix { AuthenticationId = authId, RestaurantId = restId, Role = "Owner" }; UsersManager.AddOwnerToAuthetication(authMatrix); if (newOwner) { TempData["Message"] = "You successfully inserted a restaurant in the system. You need to Login again to upgrade your new credential!!"; TempData["ErrorMessage"] = null; return(RedirectToAction("Logout", "Account")); } else { TempData["Message"] = "You successfully inserted a restaurant!!"; TempData["ErrorMessage"] = null; return(RedirectToAction("Profile", "Account")); } } else { TempData["Message"] = null; TempData["ErrorMessage"] = "Sorry!! The Restaurant's name is already registered. Choose another Restaurant's Name."; return(RedirectToAction("RestaurantCreate", "Account")); } }