예제 #1
0
        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"));
        }
예제 #2
0
        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"));
        }