示例#1
0
        private async Task <ShiftDto> CreateShift()
        {
            var sheriffId = Guid.NewGuid();
            await Db.Location.AddAsync(new Location { Id = 50000, AgencyId = "zz", Timezone = "America/Vancouver" });

            await Db.Sheriff.AddAsync(new Sheriff { Id = sheriffId, HomeLocationId = 50000, FirstName = "First", LastName = "Sheriff", IsEnabled = true });

            await Db.SaveChangesAsync();

            var shiftDto = new ShiftDto
            {
                ExpiryDate            = DateTimeOffset.UtcNow, // should be null.
                SheriffId             = sheriffId,             // should be null.
                StartDate             = DateTimeOffset.UtcNow,
                EndDate               = DateTimeOffset.UtcNow.AddHours(5),
                Sheriff               = new SheriffDto(),
                AnticipatedAssignment = null,
                Location              = new LocationDto {
                    Id = 55, AgencyId = "55"
                },
                LocationId = 50000,
                Timezone   = "America/Edmonton"
            };

            return(shiftDto);
        }
        public void Should_Map_ShiftDto_to_Shift()
        {
            // Arrange
            var _mShift = new Mock <Shift>();

            var shiftDto = new ShiftDto
            {
                IsActive        = true,
                IsAssigned      = true,
                ShiftTemplateId = 1,
                CalendarResourceRequirementId = 1,
                StartDate  = new DateTime(),
                EndDate    = new DateTime(),
                EmployeeId = 1
            };

            // Act
            CommonHelperAppService.MapDtoToEntityForUpdating(shiftDto, _mShift.Object);

            // Assert
            Assert.AreEqual(shiftDto.IsActive, _mShift.Object.IsActive);
            Assert.AreEqual(shiftDto.IsAssigned, _mShift.Object.IsAssigned);
            Assert.AreEqual(shiftDto.ShiftTemplateId, _mShift.Object.ShiftTemplateId);
            Assert.AreEqual(shiftDto.StartDate, _mShift.Object.StartDate);
            Assert.AreEqual(shiftDto.EndDate, _mShift.Object.EndDate);
            Assert.AreEqual(shiftDto.EmployeeId, _mShift.Object.EmployeeId);
        }
 public OvertimeShift(ShiftDto shiftDto)
 {
     _dto = shiftDto;
     if (shiftDto.LayerCollection==null) return;
     IList<OvertimeLayerDto> activityLayerDtos = new List<OvertimeLayerDto>(shiftDto.LayerCollection.OfType<OvertimeLayerDto>());
     foreach (OvertimeLayerDto activityLayerDto in activityLayerDtos)
     {
         LayerCollection.Add(new OvertimeLayer(activityLayerDto));
     }
 }
示例#4
0
 public static void MapDtoToEntityForUpdating(ShiftDto shiftDto, Shift shift)
 {
     shift.IsActive        = shiftDto.IsActive;
     shift.IsAssigned      = shiftDto.IsAssigned;
     shift.ShiftTemplateId = shiftDto.ShiftTemplateId;
     shift.CalendarResourceRequirementId = shiftDto.CalendarResourceRequirementId;
     shift.EmployeeId = shiftDto.EmployeeId;
     shift.StartDate  = shiftDto.StartDate;
     shift.EndDate    = shiftDto.EndDate;
 }
        public bool CheckIfShiftExistsForResourceReq(ShiftDto shiftDto)
        {
            var existingShift = _unitOfWork.ShiftRepository.Get(s => s.IsActive &&
                                                                ((s.StartDate == shiftDto.StartDate && s.EndDate == shiftDto.EndDate) ||
                                                                 (s.StartDate <= shiftDto.StartDate && s.EndDate >= shiftDto.EndDate)) &&
                                                                s.CalendarResourceRequirementId == shiftDto.CalendarResourceRequirementId)
                                .FirstOrDefault();

            if (existingShift != null)
            {
                return(true);
            }

            return(false);
        }
        // CRUD
        public void Create(ShiftDto shiftDto, long userId)
        {
            var shift = Mapper.Map <Shift>(shiftDto);

            _unitOfWork.ShiftRepository.Create(shift);
            _unitOfWork.Save();

            // Audit
            _auditLogAppService.Audit(
                AppConstants.ActionTypeCreate,
                AppConstants.ShiftTableName,
                userId,
                shift.Id);

            // TEMP FOR BALDOCK
            //SendTempEmailToMaddie(shiftDto);
        }
        public void Update(ShiftDto shiftDto, long userId)
        {
            var shift = _unitOfWork.ShiftRepository.GetById(shiftDto.Id);

            if (shift.StartDate > DateTime.Now)
            {
                CommonHelperAppService.MapDtoToEntityForUpdating(shiftDto, shift);

                _unitOfWork.ShiftRepository.Update(shift);
                _unitOfWork.Save();

                // Audit
                _auditLogAppService.Audit(
                    AppConstants.ActionTypeUpdate,
                    AppConstants.ShiftTableName,
                    userId,
                    shift.Id);

                // TEMP FOR BALDOCK
                SendTempEmailToMaddie(shiftDto);
            }
        }
        private void SendTempEmailToMaddie(ShiftDto shiftDto)
        {
            // TEMP BITS FOR BALDOCK ###################################################################################
            var mosName = string.Empty;

            // get user details from employeeId
            if (shiftDto.EmployeeId != null)
            {
                var employee = _unitOfWork.EmployeeRepository.GetById(shiftDto.EmployeeId);
                employee.User = _unitOfWork.UserRepository.GetById(employee.UserId);
                mosName       = employee.User.Firstname + " " + employee.User.Lastname;
            }

            var tempShiftTemplate = _unitOfWork.ShiftTemplateRepository.GetById(shiftDto.ShiftTemplateId);
            var tempSite          = _unitOfWork.SiteRepository.GetById(tempShiftTemplate.SiteId);
            var siteName          = tempSite.Name;

            if (tempShiftTemplate.SubSiteId != null)
            {
                var tempSubSite = _unitOfWork.SubSiteRepository.GetById(tempShiftTemplate.SubSiteId);
                siteName = tempSubSite.Name;
            }

            var tempEmailDto = new TempMaddieEmailDto
            {
                ShiftEndDateTime    = shiftDto.EndDate.ToString(),
                ShiftStartDateTime  = shiftDto.StartDate.ToString(),
                ShiftLocation       = siteName,
                ShiftNewStaffMember = mosName,
                ShiftOldStaffMember = shiftDto.TempCurrentStaffMember,
                ResourceTypeName    = shiftDto.TempResourceTypeName
            };

            // TEMP EMAIL - send details about shift and changes from here
            MailerService.SendTempMaddieEmail(tempEmailDto);
            // ########################################################################################################
        }
示例#9
0
        public T Invoke(TimeSpan startTime, TimeSpan endTime, DateTime shiftDate, int waiterId, int restaurantId)
        {
            Guard.InstanceNotNull(OnComplete, "OnComplete");

            var shift = new ShiftDto();

            shift.StartTime = shiftDate.Add(startTime);
            //if end time is smaller than start then it spans 2 days and therefor and extra day is added to the date
            if (endTime < startTime)
            {
                shiftDate = shiftDate.AddDays(1);
            }
            shift.EndTime = shiftDate.Add(endTime);

            shift.Restaurant = new RestaurantDto {
                Id = restaurantId
            };
            shift.Staff = new StaffDto()
            {
                Id = waiterId
            };

            var saveShiftResponse = serviceRegistry.ShiftService.SaveShift(new SaveShiftRequest {
                Shift = shift
            });
            var shiftsResponse = serviceRegistry.ShiftService.LoadShifts(new LoadShiftsRequest()
            {
                FromDate = shift.StartTime, ToDate = shift.EndTime, RestaurantId = restaurantId, StaffId = waiterId
            });
            var notifications = saveShiftResponse.NotificationCollection;

            return(OnComplete(new ShiftsResultViewModel(shiftsResponse.Shifts)
            {
                Notifications = notifications
            }));
        }
示例#10
0
 public virtual void UpdateShift(ShiftDto shift)
 {
     Domain.Shift model = AutoMapper.Mapper.Map <Domain.Shift>(shift);
     _ShiftRepository.Update(model);
 }
示例#11
0
 public virtual void AddShift(ShiftDto shift)
 {
     Domain.Shift model = AutoMapper.Mapper.Map <Domain.Shift>(shift);
     _ShiftRepository.Insert(model);
 }