public static void CreateUserProject(UsersProjectModel userProject)
        {
            DateTime myDate = DateTimeHelper.Today();

            DataMapping.Entities.UserProfile user = UserProfilesLogic.GetUserByUserName(userProject.UserName);
            userProject.UserId = user.UserId;
            UsersProjectRepositories.CreateUserProject(userProject, myDate);
        }
Example #2
0
        public static WorkFromHomeModel CreateWorkFomHomeModel(bool isAdmin, int userId)
        {
            WorkFromHomeModel model = new WorkFromHomeModel()
            {
                WorkFromHomeDay       = new WorkFromHomeDay(),
                RemainingDaysPerMonth = (int)WorkFromHomeDaysCount.MaxDaysPerMonth
            };

            model.WorkFromHomeDay.UserProfile    = UserProfilesLogic.GetUserById(userId);
            model.WorkFromHomeDay.EmployeeUserId = userId;
            model.WorkFromHomeDay.Date           = DateTimeHelper.Today();
            model.WorkFromHomeDay.StatusId       = isAdmin
                    ? (int)EVacationStatus.Approved
                    : (int)EVacationStatus.Pending;
            int totalTakenDaysPerYear = WorkFromHomeReopsitories.GetEmployeeWorkFromHomeDaysPerYear(userId, DateTimeHelper.Today());
            int vacationMaxDays       = (int)WorkFromHomeDaysCount.MAxDaysPerYEars;

            model.RemainingDaysPerYear = vacationMaxDays - totalTakenDaysPerYear;
            if (model.RemainingDaysPerMonth < 1)
            {
                model.ErrorMessage = "Can not Take or Request more than " + vacationMaxDays + " Days Per Year.";
                model.Succeeded    = false;
                return(model);
            }
            int totalTakenDaysPerMonth = WorkFromHomeReopsitories.GetUserWorkFromHomeDaysPerMonth(userId, DateTimeHelper.Today());

            model.RemainingDaysPerMonth = (int)WorkFromHomeDaysCount.MaxDaysPerMonth - totalTakenDaysPerMonth;
            if (model.RemainingDaysPerMonth < 1)
            {
                model.ErrorMessage = "Can not Take or Request more than " + (int)WorkFromHomeDaysCount.MaxDaysPerMonth + " Days Per Month.";
                model.Succeeded    = false;
                return(model);
            }

            model.Succeeded = true;
            return(model);
        }