Exemple #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"));
        }
Exemple #2
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"));
        }
        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"));
            }
        }