public IList <ScheduleEntryBaseDTO> SaveScheduleEntriesRange(Token token, SaveScheduleEntryRangeParam saveScheduleEntryRangeParam) { var securityInfo = SecurityManager.EnsureAuthentication(token); var service = new ScheduleEntryService(Session, securityInfo, Configuration); return(service.SaveScheduleEntryRange(saveScheduleEntryRangeParam)); }
public SaveScheduleEntriesWindow(SaveScheduleEntryRangeParam param) { viewModel = new SaveScheduleEntriesViewModel(this, param); DataContext = viewModel; InitializeComponent(); Binding binding = new Binding("CanSave"); usrProgressIndicatorButtons1.OkButton.SetBinding(Button.IsEnabledProperty, binding); }
SaveScheduleEntryRangeParam createSaveParam() { SaveScheduleEntryRangeParam param = new SaveScheduleEntryRangeParam(); param.Entries.AddRange(Entries.Select(x => x.Item)); param.StartDay = StartDate.ToUniversalTime(); param.EndDay = EndDate.AddDays(1).ToUniversalTime(); return(param); }
public void Validate_SaveScheduleEntryRangeParam_StartDayGreaterEndDay() { IBodyArchitectAccessService service = CreateServiceProxy(AddressHeader.CreateAddressHeader("APIKey", "", "EB17BC2A-94FD-4E65-8751-15730F69E7F5")); var sessionData = service.Login(ClientInformation, "test_user", "pwd".ToSHA1Hash()); var param = new SaveScheduleEntryRangeParam(); param.StartDay = DateTime.UtcNow; param.EndDay = DateTime.UtcNow.AddDays(-2); service.SaveScheduleEntriesRange(sessionData.Token, param); }
public void Validate_SaveScheduleEntryRangeParam_ActivityIdIsNull() { IBodyArchitectAccessService service = CreateServiceProxy(AddressHeader.CreateAddressHeader("APIKey", "", "EB17BC2A-94FD-4E65-8751-15730F69E7F5")); var sessionData = service.Login(ClientInformation, "test_user", "pwd".ToSHA1Hash()); var param = new SaveScheduleEntryRangeParam(); param.StartDay = DateTime.UtcNow; param.EndDay = DateTime.UtcNow.AddDays(2); var dto = new ScheduleEntryDTO(); dto.StartTime = param.StartDay; dto.EndTime = dto.StartTime + TimeSpan.FromHours(1); param.Entries.Add(dto); service.SaveScheduleEntriesRange(sessionData.Token, param); }
public void SaveAndCopy() { if (!UIHelper.EnsureInstructorLicence()) { return; } SaveScheduleEntryRangeParam param = createSaveParam(); var dlg = new SaveScheduleEntriesWindow(param); if (dlg.ShowDialog() == true) { //refresh reminders ReminderItemsReposidory.Instance.ClearCache(); ChampionshipsReposidory.Instance.Reset(); BAMessageBox.ShowInfo("ScheduleEntriesDesignViewModel_SaveAndCopy_Finished".TranslateInstructor(), dlg.Result.Count); } }
public void Save() { if (!UIHelper.EnsureInstructorLicence()) { return; } SaveScheduleEntryRangeParam param = createSaveParam(); parentView.RunAsynchronousOperation(delegate { try { var items = ServiceManager.SaveScheduleEntriesRange(param).ToList(); originalEntries = items.StandardClone().ToArray(); //refresh reminders ReminderItemsReposidory.Instance.ClearCache(); ChampionshipsReposidory.Instance.Reset(); parentView.SynchronizationContext.Send(delegate { fillAppointments(items); IsModified = false; }, null); } catch (ValidationException ex) { parentView.SynchronizationContext.Send(state => BAMessageBox.ShowValidationError(ex.Results), null); } catch (AlreadyOccupiedException ex) { parentView.SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, "AlreadyOccupiedException_ScheduleEntriesDesignViewModel_Save".TranslateInstructor(), ErrorWindow.MessageBox), null); } catch (LicenceException ex) { parentView.SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, "ErrInstructorAccountRequired".TranslateInstructor(), ErrorWindow.MessageBox), null); } catch (DeleteConstraintException ex) { parentView.SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, "DeleteConstraintException_ScheduleEntriesDesignViewModel_Save".TranslateInstructor(), ErrorWindow.MessageBox), null); } catch (Exception ex) { parentView.SynchronizationContext.Send(state => ExceptionHandler.Default.Process(ex, "Exception_ScheduleEntriesDesignViewModel_Save".TranslateInstructor(), ErrorWindow.EMailReport), null); } }); }
public SaveScheduleEntriesViewModel(IBAWindow parent, SaveScheduleEntryRangeParam param) { this.parent = parent; this.param = param; }
public IList <ScheduleEntryBaseDTO> SaveScheduleEntryRange(SaveScheduleEntryRangeParam saveScheduleEntryRangeParam) { DateTime startDate = saveScheduleEntryRangeParam.StartDay; DateTime endDate = saveScheduleEntryRangeParam.EndDay.AddDays(1); Log.WriteWarning("SaveScheduleEntriesRange:Username={0},Start={1},End={2}", SecurityInfo.SessionData.Profile.UserName, saveScheduleEntryRangeParam.StartDay, saveScheduleEntryRangeParam.EndDay); if (!SecurityInfo.Licence.IsInstructor) { throw new LicenceException("This feature is allowed for Instructor account"); } if (saveScheduleEntryRangeParam.Entries.Where(x => x.StartTime < startDate).Count() > 0 || saveScheduleEntryRangeParam.Entries.Where(x => x.EndTime > endDate).Count() > 0) { throw new ArgumentOutOfRangeException("Entries are out of range StartDay and EndDay"); } //determine if we should copy instead of save bool copy = saveScheduleEntryRangeParam.CopyStart != null && saveScheduleEntryRangeParam.CopyEnd != null; var newDb = saveScheduleEntryRangeParam.Entries.Map <IList <ScheduleEntryBase> >(); using (var trans = Session.BeginSaveTransaction()) { var dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); IList <ScheduleEntryBase> itemsToSave; if (copy) { //if((saveScheduleEntryRangeParam.CopyStart.Value-saveScheduleEntryRangeParam.StartDay).TotalDays<7 || // (saveScheduleEntryRangeParam.CopyEnd.Value - saveScheduleEntryRangeParam.EndDay).TotalDays < 7) //{ // throw new ArgumentException("Copy start and end range must be at least one week after source range"); //} //var count =Session.QueryOver<ScheduleEntry>().Where(x =>x.StartTime >= saveScheduleEntryRangeParam.CopyStart.Value && x.EndTime <= saveScheduleEntryRangeParam.CopyEnd.Value && x.Profile == dbProfile).RowCount(); //if (count>0) //{ // throw new AlreadyOccupiedException("Destination days are occupied already"); //} var count = Session.QueryOver <ScheduleEntry>().Where(x => x.StartTime >= saveScheduleEntryRangeParam.CopyStart.Value && x.EndTime <= saveScheduleEntryRangeParam.CopyEnd.Value && x.Profile == dbProfile).List(); if (count.Count > 0) { throw new AlreadyOccupiedException("Destination days are occupied already"); } itemsToSave = newDb; } else { var db = Session.QueryOver <ScheduleEntryBase>().Where(x => x.StartTime >= startDate && x.EndTime < endDate && x.Profile == dbProfile).List(); var comparer = new CollectionComparer <ScheduleEntryBase>(newDb, db); foreach (var entry in comparer.RemovedItems) { if (entry.IsLocked) { throw new DeleteConstraintException("Cannot delete schedule entry"); } Session.Delete(entry); } itemsToSave = comparer.GetForSaveItems(); } for (int index = 0; index < itemsToSave.Count; index++) { var entry = itemsToSave[index]; ScheduleEntryBase dbOldEntry = null; if (entry.GlobalId != Guid.Empty) { dbOldEntry = Session.QueryOver <ScheduleEntryBase>().Fetch(x => x.Reminder).Eager.Where(x => x.GlobalId == entry.GlobalId).SingleOrDefault(); entry.Reservations = dbOldEntry.Reservations; entry.Reminder = dbOldEntry.Reminder; if (!copy && entry.IsLocked) {//if we are in saving mode and this entry is locked then skip to the next one itemsToSave[index] = dbOldEntry; continue; } } if (dbOldEntry == null) { entry.Profile = dbProfile; dbOldEntry = entry; } var scheduleEntry = entry as ScheduleEntry; if (dbOldEntry.Profile != dbProfile) { throw new CrossProfileOperationException(); } if (scheduleEntry != null && scheduleEntry.CustomerGroup != null && scheduleEntry.CustomerGroup.Profile != dbProfile) { throw new CrossProfileOperationException("Group not belong to this user"); } if (scheduleEntry != null && scheduleEntry.Activity.Profile != dbProfile) { throw new CrossProfileOperationException("Activity is not belong to this user"); } if (itemsToSave.Where(x => x != entry && ( x.StartTime <= entry.StartTime && x.EndTime > entry.StartTime || x.StartTime < entry.EndTime && x.EndTime >= entry.EndTime)) .Count() > 0) { throw new AlreadyOccupiedException(); } var dto = saveScheduleEntryRangeParam.Entries[newDb.IndexOf(entry)]; //if (dto.RemindBefore!=null) //{ // if(entry.Reminder==null) // { // entry.Reminder=new ReminderItem(); // } // entry.Reminder.Profile = dbProfile; // entry.Reminder.DateTime = entry.StartTime; // entry.Reminder.RemindBefore = dto.RemindBefore==TimeSpan.Zero?(TimeSpan?) null:dto.RemindBefore.Value; // entry.Reminder.Name = string.Format("{0}: {1}", entry.Activity.Name,entry.StartTime); // entry.Reminder.Type = ReminderType.ScheduleEntry; //} if (dto.RemindBefore != null) { ReminderService.CreateReminder <ScheduleEntryDTO>(Session, entry, dto.RemindBefore, dbProfile, entry.StartTime, ReminderType.ScheduleEntry); } entry.Profile = dbProfile; if (dto.MyPlaceId == null) { entry.MyPlace = Session.QueryOver <MyPlace>().Where(x => x.Profile == dbProfile && x.IsDefault).SingleOrDefault(); } if (entry.MyPlace.Profile != dbProfile) { throw new CrossProfileOperationException("MyPlace not belong to this user"); } if (!copy) { //save only when we are in saving mode. in copy mode this loop is only for checking and preparing itemsToSave[index] = Session.Merge(entry); if (dto.RemindBefore != null) { itemsToSave[index].Reminder.ConnectedObject = string.Format("ScheduleEntryDTO:{0}", itemsToSave[index].GlobalId); Session.Update(itemsToSave[index].Reminder); } else if (dbOldEntry.Reminder != null) { Session.Delete(dbOldEntry.Reminder); dbOldEntry.Reminder = null; dbProfile.DataInfo.ReminderHash = Guid.NewGuid(); } } } if (copy) { itemsToSave = copyScheduleEntries(startDate, endDate, saveScheduleEntryRangeParam.CopyStart.Value, saveScheduleEntryRangeParam.CopyEnd.Value, itemsToSave, saveScheduleEntryRangeParam.Mode); } dbProfile.DataInfo.ScheduleEntryHash = Guid.NewGuid(); trans.Commit(); return(itemsToSave.Map <IList <ScheduleEntryBaseDTO> >()); } }
public IList <ScheduleEntryBaseDTO> SaveScheduleEntriesRange(Token token, SaveScheduleEntryRangeParam saveScheduleEntryRangeParam) { return(exceptionHandling(token, () => InternalService.SaveScheduleEntriesRange(token, saveScheduleEntryRangeParam))); }