Exemplo n.º 1
0
        //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"));
        }
Exemplo n.º 2
0
        //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));
        }
Exemplo n.º 3
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"));
        }