Beispiel #1
0
        //public IEnumerable<Shift> GetAllStandaredShifts()
        //{
        //    return repository.GetContext().Shifts;
        //}

        //public IEnumerable<IsolatorStaffAllocation> GetIsolatorStaffAllocations(int isolatorId, DateTime requstedDate)
        //{
        //    return repository.GetAll<IsolatorStaffAllocation>().Where(e =>
        //        e.IsolatorId == isolatorId && e.AllocatedDate.Date == requstedDate.Date && !e.IsArchived);
        //}

        public IsolatorStaffAllocationViewModel CreateAllocationViewModel(int allocationId, int isolatorId)
        {
            var allocation = repository.GetContext().IsolatorStaffAllocations.Find(allocationId);
            var model      = new IsolatorStaffAllocationViewModel()
            {
                IsolatorId = isolatorId
            };

            if (allocation != null)
            {
                model = Mapper.Map <IsolatorStaffAllocation, IsolatorStaffAllocationViewModel>(allocation);

                if (allocation.IsRecurring)
                {
                    model.RecurringType      = (RecurringTypeEnum)allocation.RecurringTypeId;
                    model.DailyRecurringType = (DailyRecurringTypeEnum)allocation.DailyRecurringTypeId;
                    model.SelectedDays       = string.IsNullOrEmpty(allocation.WeeklyRecurringWeekdays)? new int[0] : allocation.WeeklyRecurringWeekdays.Split("|").Select(p => Convert.ToInt32(p)).ToArray();
                    model.RecurrenceEndDate  = allocation.RecurringEndDate;
                }
            }

            var staffs = repository.GetContext().Users.ToList().Select(i => new { Value = i.Id, Text = i.DisplayName() });

            model.IsolatorStaffList = new SelectList(staffs, "Value", "Text", model.StaffId);

            var days = Enum.GetValues(typeof(DayOfWeek)).Cast <DayOfWeek>().Select(i => new { Value = (int)i, Text = i.ToString() });

            model.DayList = new MultiSelectList(days, "Value", "Text", model.SelectedDays);

            return(model);
        }
Beispiel #2
0
        public IsolatorStaffAllocation MapViewModelToStaffAllocation(IsolatorStaffAllocationViewModel model, string user,
                                                                     bool performSave)
        {
            var allocation = repository.GetContext().IsolatorStaffAllocations.Find(model.IsolatorStaffAllocationId);

            allocation = allocation == null?Mapper.Map <IsolatorStaffAllocationViewModel, IsolatorStaffAllocation>(model) :
                             Mapper.Map(model, allocation);

            if (model.IsRecurring)
            {
                allocation.IsRecurring      = true;
                allocation.RecurringTypeId  = (int)model.RecurringType;
                allocation.RecurringEndDate = model.RecurrenceEndDate;
                switch (model.RecurringType)
                {
                case RecurringTypeEnum.Daily:
                    allocation.DailyRecurringTypeId = (int)model.DailyRecurringType;
                    break;

                case RecurringTypeEnum.Weekly:
                    allocation.WeeklyRecurringWeekdays = string.Join("|", model.SelectedDays);
                    break;
                }
            }

            if (!performSave)
            {
                return(allocation);
            }

            if (allocation.IsolatorStaffAllocationId > 0)
            {
                allocation.SetUpdateDetails(user);
                repository.SaveExisting(allocation);
            }
            else
            {
                allocation.SetCreateDetails(user);
                repository.SaveNew(allocation);
                CreateRecurringAllocations(allocation);
            }

            return(allocation);
        }
Beispiel #3
0
        public JsonResult CreateIsolatorStaffAllocation(IsolatorStaffAllocationViewModel model)
        {
            var allocation = isolatorService.MapViewModelToStaffAllocation(model, CurrentUserName, true);

            return(Json(allocation != null));
        }