Example #1
0
        public T Invoke(IEnumerable <EditedShift> shiftEdits)
        {
            Guard.InstanceNotNull(OnSuccess, "OnSuccess");
            Guard.InstanceNotNull(OnError, "OnError");

            var notifications = NotificationCollection.CreateEmpty();
            //if shifts are marked as isSave (checked) then save them (when rendering shifts set the date and time)
            //else if they have an id delete them

            var shiftsToSave   = shiftEdits.Where(s => s.IsSave).Select(s => s.Shift).ToList();
            var shiftsToDelete = shiftEdits.Where(s => s.IsDelete).Select(s => s.Shift).ToList();

            if (shiftsToSave.Any())
            {
                foreach (var shift in shiftsToSave)
                {
                    //if end time is smaller than start then it spans 2 days and therefor and extra day is added to the date
                    if (shift.EndTime < shift.StartTime)
                    {
                        shift.EndTime = shift.EndTime.AddDays(1);
                    }
                }

                var result = serviceRegistry.ShiftService.SaveShifts(new ShiftsRequest(shiftsToSave));
                notifications += result.NotificationCollection;
            }

            if (shiftsToDelete.Any())
            {
                notifications += serviceRegistry.ShiftService.DeleteShifts(new ShiftsRequest(shiftsToDelete)).NotificationCollection;
            }

            return(notifications.HasErrors() ? OnError(notifications) : OnSuccess());
        }
Example #2
0
        public NotificationCollection ResetPassword(int userAccountId)
        {
            var result = NotificationCollection.CreateEmpty();

            var userAccount = repository.FindById <UserAccount>(userAccountId);

            if (userAccount.IsNotNull())
            {
                var newPassword = passwordGenerator.NewPassword();
                userAccount.Password = newPassword;
                userAccount.EncrypPassword(passwordEncryptor);

                result += repository.Save(userAccount);

                if (!result.HasErrors())
                {
                    var message = repository.FindBy <EmailTemplate>(e => e.TemplateName == Constants.EmailTemplates.PasswordReset).FirstOrDefault();

                    message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Password, newPassword);
                    message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Name, userAccount.FirstName);
                    message.Body = message.Body.Replace(Constants.EmailTemplatePlaceHolders.Username, userAccount.Username);

                    result += repository.Save(EmailNotification.Create(message.Subject, message.Body, SharedConfig.FromSupportEmailAddress, userAccount.EmailAddress));
                }
                if (!result.HasErrors())
                {
                    result += new Notification("Password reset successful.", NotificationSeverity.Information);
                }
            }

            return(result);
        }
Example #3
0
        private static NotificationCollection SaveNewWaiter(WaiterViewModel viewModel, IMembershipService membershipService, IShifterSystem shifterSystem)
        {
            var notifications = NotificationCollection.CreateEmpty();

            try
            {
                using (var scope = new TransactionScope())
                {
                    var createStatus = membershipService.CreateUser(viewModel.Waiter.EmailAddress, viewModel.Password, viewModel.Waiter.EmailAddress);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        notifications += CreateWaiterProfile(viewModel, shifterSystem, membershipService);
                    }
                    else
                    {
                        notifications.AddError(createStatus.ToString());
                    }

                    scope.Complete();
                }
            }
            catch (TransactionAbortedException ex)
            {
                notifications.AddError(ex.Message);
            }
            catch (ApplicationException ex)
            {
                notifications.AddError(ex.Message);
            }

            return(notifications);
        }
        public NotificationCollection DeleteStaff(int staffId)
        {
            var result = NotificationCollection.CreateEmpty();

            var staff = repository.FindById <Staff>(staffId);

            if (staff.IsNotNull())
            {
                staff.IsActive    = false;
                staff.Restaurants = new List <Restaurant>();

                var waiterShifts = repository.FindBy <Shift>(s => s.Staff.Id == staff.Id && s.IsCancelled == false && s.StartTime >= DateTime.Now);

                if (waiterShifts.Any())
                {
                    result.AddError("The staff member cannot be deleted because there are still shifts assigned to them.");
                }
                else
                {
                    result += repository.Save(staff);
                }
            }

            if (!result.HasErrors())
            {
                result.AddMessage(new Notification("Staff member deleted.", NotificationSeverity.Information));
            }

            return(result);
        }
        /// <summary>
        /// Locates relevant service that can perform persistence operations on the given IMoveAttribute and performs Save operation
        /// </summary>
        public static NotificationCollection Save(Entity entity, IShifterSystem system)
        {
            var notifications = NotificationCollection.CreateEmpty();

            var matchedType = false;

            if (entity is Waiter)
            {
                notifications += system.WaiterService.SaveWaiter(entity as Waiter);
                matchedType    = true;
            }

            if (entity is Shift)
            {
                notifications += system.ShiftService.SaveShift(entity as Shift);
                matchedType    = true;
            }

            if (entity is ShiftTimeslot)
            {
                notifications += system.ShiftTimeSlotService.SaveTimeslot(entity as ShiftTimeslot);
                matchedType    = true;
            }

            if (!matchedType)
            {
                notifications.AddError("ST002", "Type not supported");
            }

            return(notifications);
        }
Example #6
0
        public void EnsureModelHasErrorsIfAny()
        {
            var system = A.Fake <IServiceRegistry>();

            A.CallTo(() => system.ShiftService.LoadShift(null)).WithAnyArguments().Returns(new LoadShiftResponse()
            {
                Shift = new ShiftDto()
            });
            A.CallTo(() => system.ShiftService.LoadShifts(null)).WithAnyArguments().Returns(new LoadShiftCollectionResponse()
            {
                Shifts = new List <ShiftDto>()
            });
            A.CallTo(() => system.ShiftService.DeleteShift(null)).WithAnyArguments().Returns(new GenericServiceResponse {
                NotificationCollection = NotificationCollection.CreateEmpty().AddError("error")
            });

            var action = new DeleteShiftAction <dynamic>(system)
            {
                OnComplete = (m) => new { Model = m },
            };

            var result = action.Invoke(0, 0, 0).Model as ShiftsResultViewModel;

            Assert.IsTrue(result.HasErrors);
        }
Example #7
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var timeslot = entity as ShiftTimeslot;

                if (timeslot.StartTime.IsNull() || timeslot.EndTime.IsNull())
                {
                    notifications.AddError("Timeslot start time and end time are required.");
                }

                var sameTimeslots =
                    repository.FindBy <ShiftTimeslot>(
                        w => w.StartTime == timeslot.StartTime && w.EndTime == timeslot.EndTime);

                if (sameTimeslots.Any())
                {
                    notifications.AddError("Timeslot already exists.");
                }
            }

            return(notifications);
        }
Example #8
0
        public NotificationCollection SaveWallPost(WallPost wallPost)
        {
            var result = NotificationCollection.CreateEmpty();

            result += repository.Save(wallPost);

            return(result);
        }
Example #9
0
        public NotificationCollection DeleteWallPost(int wallPostId)
        {
            var result = NotificationCollection.CreateEmpty();

            result += repository.Delete <WallPost>(wallPostId);

            return(result);
        }
Example #10
0
        public NotificationCollection SaveComment(Comment comment)
        {
            var result = NotificationCollection.CreateEmpty();

            result += repository.Save(comment);

            return(result);
        }
        public GetUserRepositoriesAction(GitService.IGitService gitService, ILogger logger)
        {
            Guard.ArgumentNotNull(gitService, "gitService");
            Guard.ArgumentNotNull(logger, "logger");

            this.GitService    = gitService;
            this.Logger        = logger;
            this.Notifications = NotificationCollection.CreateEmpty();
        }
Example #12
0
        private static NotificationCollection UpdateWaiter(WaiterViewModel viewModel, IMembershipService membershipService, IShifterSystem shifterSystem)
        {
            var notifications = NotificationCollection.CreateEmpty();

            notifications += UpdatePassword(viewModel, membershipService);

            notifications += shifterSystem.WaiterService.SaveWaiter(viewModel.Waiter);

            return(notifications);
        }
        public NotificationCollection DeleteStaffUnavailability(IEnumerable <int> unavailabilityIds)
        {
            var result = NotificationCollection.CreateEmpty();

            foreach (var id in unavailabilityIds)
            {
                result += repository.Delete <StaffUnavailabilityRecord>(id);
            }

            return(result);
        }
Example #14
0
        private NotificationCollection LoadNotifications(int restaurantId)
        {
            var result        = serviceRegistry.SettingsService.LoadRestaurantNotifications(new GenericEntityRequest(restaurantId));
            var notifications = NotificationCollection.CreateEmpty();

            var messages = result.NotificationCollection.Where(n => n.Severity == NotificationSeverity.Information);

            foreach (var notification in messages)
            {
                notifications.AddMessage(notification);
            }
            return(notifications);
        }
Example #15
0
        //TODO this needs to be better
        public static NotificationCollection SaveWaiter(WaiterViewModel viewModel, IMembershipService membershipService, IShifterSystem shifterSystem)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (viewModel.Waiter.IsNew())
            {
                notifications += UpdateWaiter(viewModel, membershipService, shifterSystem);
            }
            else
            {
                notifications += SaveNewWaiter(viewModel, membershipService, shifterSystem);
            }

            return(notifications);
        }
Example #16
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var shift = entity as Shift;

                if (shift.StartTime.IsNull() || shift.EndTime.IsNull())
                {
                    notifications.AddError("A shift must have a start and end time.");
                }
            }

            return(notifications);
        }
Example #17
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var restaurant = entity as Restaurant;

                if (restaurant.Name.IsNullOrEmpty())
                {
                    notifications.AddError("The company name is required.");
                }
            }

            return(notifications);
        }
Example #18
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var staff = entity as Staff;

                if (staff.UserAccount.EmailAddress.IsNotNull() && !staff.UserAccount.EmailAddress.IsEmailAddress())
                {
                    notifications.AddError("Email address invalid.");
                }
            }

            return(notifications);
        }
Example #19
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var waiter = entity as Staff;

                if (waiter.UserAccount.FirstName.SafeTrim().IsNullOrEmpty() || waiter.UserAccount.LastName.SafeTrim().IsNullOrEmpty())
                {
                    notifications.AddError("Staff's first and last name are required.");
                }
            }

            return(notifications);
        }
Example #20
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var waiter = entity as Staff;

                if (waiter.UserAccount.ContactNumber.SafeTrim().IsNullOrEmpty())
                {
                    notifications.AddError("Staff's contact number is required.");
                }
            }

            return(notifications);
        }
Example #21
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var waiter = entity as Staff;

                if (waiter.UserAccount.IsNull() || waiter.UserAccount.Password.IsNullOrEmpty() || waiter.UserAccount.Username.IsNullOrEmpty())
                {
                    notifications.AddError("Staff must have an email address and password.");
                }
            }

            return(notifications);
        }
Example #22
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var item = entity as Waiter;

                if (item.EmailAddress.IsNull() || !item.EmailAddress.IsEmailAddress())
                {
                    notifications.AddError("Email address invalid.");
                }
            }

            return(notifications);
        }
Example #23
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var record = entity as StaffUnavailabilityRecord;
                var shiftsOnUnavailabilityDates = repository.FindBy <Shift>(s => s.Staff.Id == record.StaffId && (s.StartTime >= record.UnavailableFrom && s.StartTime <= record.UnavailableTo)); //TODO ensure it covers all combinations
                if (shiftsOnUnavailabilityDates.Any())
                {
                    notifications.AddError("Sorry you are already working during these dates.", ClientErrorCodes.Staff);
                    notifications.AddError("Sorry the staff member is already working during these dates.", ClientErrorCodes.Managers);
                }
            }

            return(notifications);
        }
Example #24
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var waiter = entity as Staff;

                var existingUsername = repository.FindBy <UserAccount>(u => u.Username == waiter.UserAccount.Username && u.Id != waiter.UserAccount.Id);

                if (existingUsername.Any())
                {
                    notifications.AddError("This username is not available.");
                }
            }

            return(notifications);
        }
Example #25
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var waiter = entity as Staff;

                var waitersWithSameEmail = repository.FindBy <Staff>(w => w.UserAccount.EmailAddress != null && w.UserAccount.EmailAddress == waiter.UserAccount.EmailAddress && w.Id != waiter.Id);

                if (waitersWithSameEmail.Any())
                {
                    notifications.AddError("Email address already exists.");
                }
            }

            return(notifications);
        }
Example #26
0
        private static NotificationCollection CreateWaiterProfile(WaiterViewModel viewModel, IShifterSystem shifterSystem, IMembershipService membershipService)
        {
            var notifications = NotificationCollection.CreateEmpty();

            var userAccount = shifterSystem.UserService.LoadUser(viewModel.Waiter.EmailAddress);

            if (userAccount.IsNotNull())
            {
                notifications += shifterSystem.WaiterService.SaveWaiter(viewModel.Waiter);

                if (notifications.HasErrors())
                {
                    membershipService.DeleteUser(userAccount.Username);
                }
            }

            return(notifications);
        }
Example #27
0
        public void EnsureViewModelHadErrorsIfSaveFailed()
        {
            var system = A.Fake <IServiceRegistry>();

            A.CallTo(() => system.ShiftTemplateService.SaveTemplates(null)).WithAnyArguments().
            Returns(new GenericServiceResponse
            {
                NotificationCollection = NotificationCollection.CreateEmpty().AddError("error")
            });

            var action = new SaveShiftTemplateAction <dynamic>(system)
            {
                OnComplete = (m) => new { Value = m },
            };

            var result = action.Invoke(new ShiftTemplateViewModel(), 1).Value as ShiftTemplateViewModel;

            Assert.IsTrue(result.Notifications.HasErrors());
        }
        /// <summary>
        /// Locates relevant service that can perform persistence operations on the given IMoveAttribute and performs Save operation
        /// </summary>
        public static NotificationCollection Save(IEnumerable <Entity> entities, IShifterSystem system)
        {
            var notifications = NotificationCollection.CreateEmpty();

            var matchedType = false;

            if (entities is IEnumerable <ShiftTemplate> )
            {
                notifications += system.ShiftTemplateService.SaveTemplates(entities as IEnumerable <ShiftTemplate>);
                matchedType    = true;
            }

            if (!matchedType)
            {
                notifications.AddError("ST001", "Type not supported");
            }

            return(notifications);
        }
        public NotificationCollection SaveConfirmedShiftDeleteNotification(IEnumerable <int> deleteNotificationIds)
        {
            var result = NotificationCollection.CreateEmpty();

            var deleteNotifications = new List <TrackedDeletedShift>();

            foreach (var notificationId in deleteNotificationIds)
            {
                var shiftAssignment = repository.FindById <TrackedDeletedShift>(notificationId);
                if (shiftAssignment.IsNotNull())
                {
                    shiftAssignment.DateStaffConfirmed = DateTime.Now;

                    deleteNotifications.Add(shiftAssignment);
                }
            }
            result = repository.Save(deleteNotifications);

            return(result);
        }
Example #30
0
        public NotificationCollection Validate(object entity, IRepository repository)
        {
            var notifications = NotificationCollection.CreateEmpty();

            if (entity.IsNotNull())
            {
                var waiter = entity as Waiter;

                var today = DateTime.Now;

                var waiterShifts = repository.FindBy <Shift>(s => s.Waiter.Id == waiter.Id && s.Date >= today);

                if (waiterShifts.Any())
                {
                    notifications.AddError("Waiter cannot be deleted because there are still shifts assigned to them.");
                }
            }

            return(notifications);
        }