Пример #1
0
        public static void AddEmployeeToRestaurant(RestaurantEmployees restaurantEmployee)
        {
            var context = new TableReadyContext();

            context.RestaurantEmployees.Add(restaurantEmployee);
            context.SaveChanges();
        }
Пример #2
0
        public static void UpdateRestaurantEmployee(RestaurantEmployees restaurantEmployee)
        {
            var context = new TableReadyContext();
            var originalRestaurantEmployee = context.RestaurantEmployees.SingleOrDefault(p => p.RestaurantId == restaurantEmployee.RestaurantId && p.EmployeeId == restaurantEmployee.EmployeeId);

            originalRestaurantEmployee.NewRequestFlag = restaurantEmployee.NewRequestFlag;
            originalRestaurantEmployee.RequestStatus  = restaurantEmployee.RequestStatus;
            originalRestaurantEmployee.StartDate      = restaurantEmployee.StartDate;
            originalRestaurantEmployee.EndDate        = restaurantEmployee.EndDate;
            originalRestaurantEmployee.Active         = restaurantEmployee.Active;
            originalRestaurantEmployee.Status         = restaurantEmployee.Status;
            context.SaveChanges();
        }
        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"));
            }
        }