/// <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); }
/// <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); }
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); }
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); }
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); }
//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); }