public EventCreateUpdateViewModel GetEventViewModel(string eventId) { var viewModel = new EventCreateUpdateViewModel(); if (eventId.IsNotEmptyString()) { eventId = eventId.FixRavenId("Events"); var existing = Session.Load <Event>(eventId); viewModel.Duration = existing.TimeSlot?.Duration; viewModel.Name = existing.Name; viewModel.GameMasterIds = existing.GameMasterIds; viewModel.SpecialRequests = existing.SpecialRequests; viewModel.Status = existing.Status; viewModel.Tags = existing.Tags; viewModel.AgeId = existing.AgeId; viewModel.Size = existing.Size; viewModel.Description = existing.Description; viewModel.Id = existing.Id; viewModel.IsSpecialPrice = existing.IsSpecialPrice; viewModel.SpecialPrice = existing.SpecialPrice; viewModel.HallTableSelector = $"{existing.HallId},{existing.HallTable}"; viewModel.ActivitySelector = $"{existing.ActivityId},{existing.SubActivityId}"; viewModel.StartTimeSelector = $"{existing.ConventionDayId},{existing.TimeSlot?.From.ToString("HH:mm", CultureInfo.InvariantCulture)}"; } else { if (viewModel.GameMasterIds == null) { viewModel.GameMasterIds = new List <string>(); } if (viewModel.Size == null) { viewModel.Size = new SizeRestriction(); } if (viewModel.Tags == null) { viewModel.Tags = new List <string>(); } viewModel.Status = EventStatus.Pending; } return(viewModel); }
private (Instant timestamp, List <UserAction> list) GetUserActions(Event model, EventCreateUpdateViewModel viewmodel) { var timestamp = SystemClock.Instance.GetCurrentInstant(); var result = new List <UserAction>(); foreach (PropertyInfo property in model.GetType().GetProperties()) { var value1 = property.GetValue(model, null); var compareProperty = viewmodel.GetType().GetProperty(property.Name); if (compareProperty != null) { var value2 = compareProperty.GetValue(viewmodel, null); var value1AsJson = value1.AsJson(); var value2AsJson = value2.AsJson(); if ((value1 is null && value2 is {}) ||
public Answer UpdateEvent(EventCreateUpdateViewModel viewmodel) { var answer = ValidateEventFields(viewmodel); if (answer.AnswerType != AnswerType.Success) { return(answer); } var model = Session.Load <Event>(viewmodel.Id); if (model == null) { return(Answer.Error("תקלה בטעינת האירוע")); } var userActions = GetUserActions(model, viewmodel); foreach (var userAction in userActions.list) { Session.Store(userAction); } model.UpdatedOn = SystemClock.Instance.GetCurrentInstant(); model.IsSpecialPrice = viewmodel.IsSpecialPrice; model.SpecialPrice = viewmodel.SpecialPrice; model.Name = viewmodel.Name; model.Description = viewmodel.Description; model.ConventionDayId = viewmodel.ConventionDayId; model.Status = viewmodel.Status; model.GameMasterIds = viewmodel.GameMasterIds; model.Size = viewmodel.Size; model.AgeId = viewmodel.AgeId; model.Tags = viewmodel.Tags; model.SpecialRequests = viewmodel.SpecialRequests; model.ActivityId = viewmodel.ActivityId; model.SubActivityId = viewmodel.SubActivityId; model.HallId = viewmodel.HallId; model.HallTable = int.Parse(viewmodel.HallTable); if (viewmodel.StartTimeSelector.IsNotEmptyString() && viewmodel.Duration.HasValue) { var timeSplit = viewmodel.StartTime.Split(':'); var hours = int.Parse(timeSplit[0]); var minutes = int.Parse(timeSplit[1]); var num = (int)viewmodel.Duration.Value / 1; var denum = (int)viewmodel.Duration.Value % 1; var startTime = new LocalTime(hours, minutes); var endTime = startTime.PlusHours(num).PlusMinutes(denum); var tempTimeSlot = new TimeSlot { From = startTime, To = endTime, Duration = viewmodel.Duration.Value }; if (model.TimeSlot.AsJson() != tempTimeSlot.AsJson()) { var action = new UserAction() { TimeStamp = userActions.timestamp, Field = "TimeSlot", DocumentId = model.Id, NewValue = tempTimeSlot.AsJson(), OldValue = model.TimeSlot.AsJson(), UserId = Actor.Me.Id }; model.TimeSlot = tempTimeSlot; Session.Store(action); } } Session.SaveChanges(); return(Answer.Success); }