public void EditEventsValidReturnsOk() { //Setup var mockEventsRepo = new Mock <IEventRepo>(); var mockEventResultsRepo = new Mock <IEventResultsRepo>(); var mockUserRepo = new Mock <IUserRepo>(); var model = new EditEventModel() { EventAge = "Junior", EventCode = "01", EventGender = "M", EventId = 1, MeetId = 1, Round = "F" }; mockEventsRepo.Setup(mER => mER.EditEvent(model)).Returns(true); var sut = new EventsController(mockEventsRepo.Object, mockEventResultsRepo.Object, mockUserRepo.Object); //Action var res = sut.EditEvent(model); //Assert res.Should().BeOfType <OkResult>(); }
public void EditEventsInvalidRoundReturnsBadRequest() { //Setup var mockEventsRepo = new Mock <IEventRepo>(); var mockEventResultsRepo = new Mock <IEventResultsRepo>(); var mockUserRepo = new Mock <IUserRepo>(); var model = new EditEventModel() { EventAge = "Junior", EventCode = "01", EventGender = "M", EventId = 1, MeetId = 1, Round = "T" }; var sut = new EventsController(mockEventsRepo.Object, mockEventResultsRepo.Object, mockUserRepo.Object); //Action var res = sut.EditEvent(model); //Assert res.Should().BeOfType <BadRequestErrorMessageResult>(); res.As <BadRequestErrorMessageResult>().Message.Should() .Be("Round must be one of the following H, F, C, S, B according to the Neutral file format"); }
public ActionResult EditEventForm(int id = 0) { List <EventLocation> locations = this._db.Query <EventLocation>("SELECT * FROM ec_locations").ToList(); locations.Insert(0, new EventLocation() { LocationName = "No Location", Id = 0 }); //Get the Event from Database CalendarEntry entry = this._db.SingleOrDefault <CalendarEntry>(id); //Create SelectList with selected location SelectList list = new SelectList(locations, "Id", "LocationName", entry.locationId); //Create Model for the View EditEventModel eem = new EditEventModel() { Id = entry.Id, title = entry.title, start = (DateTime)entry.start, description = entry.description, calendarId = entry.calendarId, allday = entry.allDay, locations = list }; if (null != entry.end) { eem.end = (DateTime)entry.end; } return(PartialView("EditEventForm", eem)); }
public void EditEventsInvalidDbReturnsBadResult() { //Setup var mockEventsRepo = new Mock <IEventRepo>(); var mockEventResultsRepo = new Mock <IEventResultsRepo>(); var mockUserRepo = new Mock <IUserRepo>(); var model = new EditEventModel() { EventAge = "Junior", EventCode = "01", EventGender = "M", EventId = 1, MeetId = 1, Round = "F" }; mockEventsRepo.Setup(mER => mER.EditEvent(model)).Returns(false); var sut = new EventsController(mockEventsRepo.Object, mockEventResultsRepo.Object, mockUserRepo.Object); //Action var res = sut.EditEvent(model); //Assert res.Should().BeOfType <BadRequestErrorMessageResult>(); res.As <BadRequestErrorMessageResult>().Message.Should().Be("Editing event failed"); }
public virtual ActionResult Add() { var model = new EditEventModel { StartDate = new ModelTime { Date = DateTime.Today, Hour = 9, Minute = 0 }, EndDate = new ModelTime { Date = DateTime.Today.AddDays(1), Hour = 18, Minute = 0 }, ApplicationConfig = new ApplicationConfigModel { CurrentVersion = "1.0", AppPassCode = Guid.NewGuid(), ReportPassCode = Guid.NewGuid(), HasGoLiveDate = false, WebServiceUri = "https://www.learning-performance.com/MyMood/", LanServiceUri = "http://192.168.100.4:8080", SyncDataInterval = 60, SyncReportInterval = 0, WarnSyncFailureAfterMins = 5, ForceUpdate = false, UpdateAppUri = "https://www.learning-performance.com/MyMood/", ReportMoodIsStaleMins = 0, ReportSplineTension = 0.5, TimeZone = TimeZoneInfo.Utc.Id, SyncMode = SyncMode.LANthenWAN } }; PopulateModelLists(model); return(PartialView(MVC.Event.Views.Edit, model)); }
//POST api/Events/EditEvent public IHttpActionResult EditEvent(EditEventModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!Gender.Contains(model.EventGender)) { return(BadRequest("Gender entered is not valid it must be either M, F, or Mix")); } if (!EventCodes.Contains(model.EventCode)) { return(BadRequest("Event Code is not valid and must be match the neutral file format standard")); } if (!Rounds.Contains(model.Round)) { return(BadRequest("Round must be one of the following H, F, C, S, B according to the Neutral file format")); } var res = _eventRepo.EditEvent(model); return(res ? (IHttpActionResult)Ok() : BadRequest("Editing event failed")); }
public ActionResult EditEventForm(EditEventModel e) { List <EventLocation> locations = this._db.Query <EventLocation>("SELECT * FROM ec_locations").ToList(); locations.Insert(0, new EventLocation() { LocationName = "No Location", Id = 0 }); SelectList list = new SelectList(locations, "Id", "LocationName", e.selectedLocation); e.locations = list; if (!ModelState.IsValid) { TempData["StatusEditEvent"] = "Invalid"; return(PartialView("EditEventForm", e)); } TempData["StatusEditEvent"] = "Valid"; CalendarEntry entry = new CalendarEntry() { allDay = e.allday, calendarId = e.calendarId, description = e.description, title = e.title, end = e.end, start = e.start, Id = e.Id, locationId = e.selectedLocation }; this._db.Update(entry); return(PartialView("EditEventForm", e)); }
private void BindEventModelToEvent(EditEventModel model, Event e) { e.Title = model.Title; e.Name = model.Name; e.ApplicationConfig.CurrentVersion = model.ApplicationConfig.CurrentVersion; e.StartDate = model.StartDate.FullDate; e.EndDate = model.EndDate.FullDate; e.ApplicationConfig.AppPassCode = model.ApplicationConfig.AppPassCode; e.ApplicationConfig.ReportPassCode = model.ApplicationConfig.ReportPassCode; e.ApplicationConfig.GoLiveDate = null; if (model.ApplicationConfig.HasGoLiveDate) { e.ApplicationConfig.GoLiveDate = model.ApplicationConfig.GoLiveDate.FullDate; } e.ApplicationConfig.WebServiceUri = model.ApplicationConfig.WebServiceUri; e.ApplicationConfig.LanServiceUri = model.ApplicationConfig.LanServiceUri; e.ApplicationConfig.SyncDataInterval = model.ApplicationConfig.SyncDataInterval; e.ApplicationConfig.SyncReportInterval = model.ApplicationConfig.SyncReportInterval; e.ApplicationConfig.WarnSyncFailureAfterMins = model.ApplicationConfig.WarnSyncFailureAfterMins; e.ApplicationConfig.ForceUpdate = model.ApplicationConfig.ForceUpdate; e.ApplicationConfig.UpdateAppUri = model.ApplicationConfig.UpdateAppUri; e.ApplicationConfig.ReportMoodIsStaleMins = model.ApplicationConfig.ReportMoodIsStaleMins; e.ApplicationConfig.ReportSplineTension = model.ApplicationConfig.ReportSplineTension; e.ApplicationConfig.TimeZone = model.ApplicationConfig.TimeZone; e.ApplicationConfig.SyncMode = model.ApplicationConfig.SyncMode; e.ConvertAllToUTC(); }
public void UpdateEvent(int eventId, EditEventModel model) { var evt = GetEvent(eventId); model.MapTo(evt); repository.SaveChanges(); }
public void EditEventsInvalidGenderReturnsBadRequest() { //Setup var mockEventsRepo = new Mock <IEventRepo>(); var mockEventResultsRepo = new Mock <IEventResultsRepo>(); var mockUserRepo = new Mock <IUserRepo>(); var model = new EditEventModel() { EventAge = "Junior", EventCode = "01", EventGender = "TEST", EventId = 1, MeetId = 1, Round = "F" }; var sut = new EventsController(mockEventsRepo.Object, mockEventResultsRepo.Object, mockUserRepo.Object); //Action var res = sut.EditEvent(model); //Assert res.Should().BeOfType <BadRequestErrorMessageResult>(); res.As <BadRequestErrorMessageResult>().Message.Should() .Be("Gender entered is not valid it must be either M, F, or Mix"); }
public void EditEventsInvalidEventCodeReturnsBadRequest() { //Setup var mockEventsRepo = new Mock <IEventRepo>(); var mockEventResultsRepo = new Mock <IEventResultsRepo>(); var mockUserRepo = new Mock <IUserRepo>(); var model = new EditEventModel() { EventAge = "Junior", EventCode = "55", EventGender = "M", EventId = 1, MeetId = 1, Round = "F" }; var sut = new EventsController(mockEventsRepo.Object, mockEventResultsRepo.Object, mockUserRepo.Object); //Action var res = sut.EditEvent(model); //Assert res.Should().BeOfType <BadRequestErrorMessageResult>(); res.As <BadRequestErrorMessageResult>().Message.Should() .Be("Event Code is not valid and must be match the neutral file format standard"); }
public ActionResult Edit(int id, EditEventModel model) { if (ModelState.IsValid) { service.UpdateEvent(id, model); return(RedirectToAction("Index")); } return(View(service.GetEditEventModel(id))); }
private async Task EditEvent() { var editModel = EditEventModel.GetFromEventModel(Item); var navParams = new Dictionary <string, object>() { { "Event", editModel } }; await NavigateTo(Pages.EditEvent, navParams : navParams); }
private void PopulateModelLists(EditEventModel model) { model.AvailableSyncModes = EnumHelper.GetSelectListItemsFor <SyncMode>(); model.AvailableTimeZones = (from tx in TimeZoneInfo.GetSystemTimeZones() select new SelectListItem { Text = tx.DisplayName, Value = tx.Id, }) .ToArray(); }
public bool EditEvent(EditEventModel model) { var _eventToUpdate = _db.Events.Single(e => e.EventId == model.EventId); _eventToUpdate.EventAge = model.EventAge; _eventToUpdate.EventCode = model.EventCode; _eventToUpdate.EventGender = model.EventGender; _eventToUpdate.MeetId = model.MeetId; _eventToUpdate.Round = model.Round; var res = _db.SaveChanges(); return res > 0; }
public void Item(int id, EditEventModel input) { var notifier = new EmailNotifier(); switch (input.Action) { case EventEditAction.Assign: Repository.AssignManager(id, HttpContext.User.Identity.Name); break; case EventEditAction.Unassign: Repository.AssignManager(id, null); notifier.LeadCancellationNotification(Repository, Repository.GetEventById(id)); break; case EventEditAction.Edit: if (HttpContext.User.IsInRole("Admin")) { User manager = null; if (input.ManagerId != null) { manager = Repository.GetUserById(input.ManagerId.Value); } Event e = Repository.GetEventById(id); e.EventDescription = input.Description; e.EventStartDateTime = DateTime.ParseExact(input.Date + " " + input.StartTime, "M/d/yyyy HH:mm", CultureInfo.InvariantCulture); e.EventEndDateTime = DateTime.ParseExact(input.Date + " " + input.EndTime, "M/d/yyyy HH:mm", CultureInfo.InvariantCulture); e.EventTitle = input.Title; e.User = manager; e.EventManagerId = input.ManagerId; Repository.SaveEvent(e); } break; case EventEditAction.Delete: if (HttpContext.User.IsInRole("Admin")) { Event @event = Repository.GetEventById(id); string email = (@event != null && @event.User != null) ? @event.User.UserEmail : string.Empty; Repository.DeleteEventById(id); if (!string.IsNullOrWhiteSpace(email)) { notifier.EventCancellationNotification(Repository, @event, @event.User.UserEmail); } } break; } }
public ActionResult EditEventForm(EditEventModel e) { //Get locations List <EventLocation> locations = this._db.Query <EventLocation>("SELECT * FROM ec_locations").ToList(); locations.Insert(0, new EventLocation() { LocationName = "No Location", Id = 0 }); SelectList list = new SelectList(locations, "Id", "LocationName", e.selectedLocation); e.locations = list; //Get Descriptions for Event Dictionary <string, EventDesciption> descriptions = this._db.Query <EventDesciption>("SELECT * FROM ec_eventdescriptions WHERE eventid = @0", e.Id).ToDictionary(x => x.CultureCode); List <ILanguage> languages = Services.LocalizationService.GetAllLanguages().ToList(); foreach (var lang in languages) { if (!descriptions.ContainsKey(lang.CultureInfo.ToString())) { descriptions.Add(lang.CultureInfo.ToString(), new EventDesciption() { CultureCode = lang.CultureInfo.ToString(), EventId = e.Id, Id = 0, Type = (int)EventType.Normal, CalendarId = e.calendarId }); } } e.Descriptions = descriptions; if (!ModelState.IsValid) { TempData["StatusEditEvent"] = "Invalid"; return(PartialView("EditEventForm", e)); } TempData["StatusEditEvent"] = "Valid"; CalendarEntry entry = new CalendarEntry() { allDay = e.allday, calendarId = e.calendarId, description = e.description, title = e.title, end = e.end, start = e.start, Id = e.Id, locationId = e.selectedLocation }; this._db.Update(entry); return(PartialView("EditEventForm", e)); }
private EditEventModel CreateModel(string name, string letter) { var model = new EditEventModel(); model.Event = DataRepository.GetEvent(name); // exclude bands on the list model.MyBands = DataRepository.GetBandRelationsByUser(loggedUserGuid, 1).Where(b => !model.Event.Bands.Select(m => m.Band.BandId).Contains(b.Band.BandId)).Select(b => b.Band); // exclude my bands model.OtherBands = DataRepository.GetBandsByLetter(letter).Where(b => !model.MyBands.Select(m => m.BandId).Contains(b.BandId)); return(model); }
public void List(EditEventModel input) { if (HttpContext.User.IsInRole("Admin")) { var e = new Event { EventDescription = input.Description, EventStartDateTime = DateTime.ParseExact(input.Date + " " + input.StartTime, "M/d/yyyy HH:mm", CultureInfo.InvariantCulture), EventEndDateTime = DateTime.ParseExact(input.Date + " " + input.EndTime, "M/d/yyyy HH:mm", CultureInfo.InvariantCulture), EventTitle = input.Title, EventManagerId = input.ManagerId }; Repository.SaveEvent(e); } }
public ActionResult EditEventForm(int id = 0) { List <EventLocation> locations = this._db.Query <EventLocation>("SELECT * FROM ec_locations").ToList(); locations.Insert(0, new EventLocation() { LocationName = "No Location", Id = 0 }); //Get the Event from Database CalendarEntry entry = this._db.SingleOrDefault <CalendarEntry>(id); //Create SelectList with selected location SelectList list = new SelectList(locations, "Id", "LocationName", entry.locationId); //Create Model for the View EditEventModel eem = new EditEventModel() { Id = entry.Id, title = entry.title, start = (DateTime)entry.start, description = entry.description, calendarId = entry.calendarId, allday = entry.allDay, locations = list }; if (null != entry.end) { eem.end = (DateTime)entry.end; } //Get Descriptions for Event Dictionary <string, EventDesciption> descriptions = this._db.Query <EventDesciption>("SELECT * FROM ec_eventdescriptions WHERE eventid = @0 AND type = @1 AND calendarid = @2", id, 0, entry.calendarId).ToDictionary(x => x.CultureCode); List <ILanguage> languages = Services.LocalizationService.GetAllLanguages().ToList(); foreach (var lang in languages) { if (!descriptions.ContainsKey(lang.CultureInfo.ToString())) { descriptions.Add(lang.CultureInfo.ToString(), new EventDesciption() { CultureCode = lang.CultureInfo.ToString(), EventId = eem.Id, Id = 0, CalendarId = entry.calendarId, Type = (int)EventType.Normal }); } } eem.Descriptions = descriptions; return(PartialView("EditEventForm", eem)); }
/// <summary> /// Maps the specified new event. /// </summary> /// <param name="edit">The edit.</param> /// <returns>Event.</returns> private Event MapEditEventModel(Event e, EditEventModel edit) { Func <string, string, int, DateTime> toUtc = (d, t, i) => ConvertToUtc(DateTime.Parse(d + " " + t), i); e.FormattedNumber = edit.Formatted; e.BackgroundColor = edit.BackgroundColor; e.TextColor = edit.TextColor; e.Name = edit.Name; e.StartTime = toUtc(edit.DateStart, edit.TimeStart, edit.Timezone); e.Number = edit.Number; e.EndTime = toUtc(edit.DateEnd, edit.TimeEnd, edit.Timezone); e.Timezone = new Timezone { Id = edit.Timezone }; return(e); }
public HttpResponseMessage EditEvent(EditEventModel model) { if (model != null && ModelState.IsValid) { var evt = _calendarEventRepository.GetEvent(model.EventId); if (evt == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "event not found")); } var confirmationChanged = model.IsConfirmed && !evt.Confirmed; evt.StartsAt = DateTime.Parse(model.Start); evt.EndsAt = DateTime.Parse(model.End); evt.Name = model.Title; evt.Description = model.Description; evt.Location = model.Location; evt.IsPrivate = model.IsPrivate; evt.Confirmed = model.IsConfirmed; _calendarEventRepository.Save(); // notification if (confirmationChanged) { var msg = string.Format("Termin \"{0}\" findet wirklich statt.", evt.Name); var subscriptions = _calendarSubscriptionRepository.GetAllSubscriptionsByCalendarId(evt.CalendarId); foreach (var subscription in subscriptions) { var notification = new Notification { UserId = subscription.SubscriberId, Message = msg }; _notificationRepository.InsertNotification(notification); } _notificationRepository.Save(); } return(Request.CreateResponse(HttpStatusCode.Accepted, evt.EventId)); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "invalid data")); }
public async Task <IActionResult> Edit(int id, EditEventModel @event) { if (id != @event.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var newEvent = events.GetSingle(e => e.Id == id); if (usermanager.GetUserId(User) != newEvent.UserId) { return(NotFound()); } ; newEvent.Id = @event.Id; newEvent.Name = @event.Name; newEvent.Place = @event.Place; newEvent.StartTime = @event.StartTime; newEvent.ImageUrl = @event.ImageUrl; newEvent.Description = @event.Description; newEvent.UserId = usermanager.GetUserId(User); events.Update(newEvent); } catch (DbUpdateConcurrencyException) { if (!EventExists(@event.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(@event)); }
public virtual ActionResult Edit(Guid id) { var e = GetEvent(id); var config = new ApplicationConfigModel() { AppPassCode = e.ApplicationConfig.AppPassCode, CurrentVersion = e.ApplicationConfig.CurrentVersion, ForceUpdate = e.ApplicationConfig.ForceUpdate, UpdateAppUri = e.ApplicationConfig.UpdateAppUri, HasGoLiveDate = e.ApplicationConfig.GoLiveDate.HasValue, GoLiveDate = new ModelTime { Date = e.ApplicationConfig.GoLiveDateLocal ?? DateTime.Now }, LanServiceUri = e.ApplicationConfig.LanServiceUri, ReportMoodIsStaleMins = e.ApplicationConfig.ReportMoodIsStaleMins, ReportPassCode = e.ApplicationConfig.ReportPassCode, ReportSplineTension = e.ApplicationConfig.ReportSplineTension, SyncDataInterval = e.ApplicationConfig.SyncDataInterval, SyncMode = e.ApplicationConfig.SyncMode, SyncReportInterval = e.ApplicationConfig.SyncReportInterval, TimeZone = e.ApplicationConfig.TimeZone, WarnSyncFailureAfterMins = e.ApplicationConfig.WarnSyncFailureAfterMins, WebServiceUri = e.ApplicationConfig.WebServiceUri }; var model = new EditEventModel() { Id = e.Id, Name = e.Name, Title = e.Title, StartDate = new ModelTime { Date = e.StartDateLocal ?? DateTime.Today }, EndDate = new ModelTime { Date = e.EndDateLocal ?? DateTime.Today }, ApplicationConfig = config }; PopulateModelLists(model); return(PartialView(model)); }
public virtual ActionResult Save(EditEventModel model) { if (ModelState.IsValid) { try { Event e; if (model.Id == Guid.Empty) { if (db.Get <Event>().Any(x => x.Name.Equals(model.Name, StringComparison.InvariantCultureIgnoreCase))) { ModelState.AddModelError("Name", "An event with that name already exists"); } else { e = new Event(model.Name, model.Title); BindEventModelToEvent(model, e); db.Add(e); db.SaveChanges(); } } else { e = GetEvent(model.Id); BindEventModelToEvent(model, e); db.SaveChanges(); } } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } } if (!ModelState.IsValid) { PopulateModelLists(model); return(Json(new { success = false, formWithErrorMessages = this.RenderPartialViewToString(MVC.Event.Views.Edit, model) })); } return(Json(new { success = true })); }
public void EditEventsInvalidModelReturnsBadRequest() { //Setup var mockEventsRepo = new Mock <IEventRepo>(); var mockEventResultsRepo = new Mock <IEventResultsRepo>(); var mockUserRepo = new Mock <IUserRepo>(); var model = new EditEventModel(); var sut = new EventsController(mockEventsRepo.Object, mockEventResultsRepo.Object, mockUserRepo.Object); sut.ModelState.AddModelError("EventId", "EventId is invalid"); //Action var res = sut.EditEvent(model); //Assert res.Should().BeOfType <InvalidModelStateResult>(); res.As <InvalidModelStateResult>().ModelState.IsValid.Should().BeFalse(); }
// POST: oruinsparkwebapi.azurewebsites.net/api/GroupEvent/EditEvent/ public HttpResponseMessage EditEvent([FromBody] EditEventModel editEventModel) { Event eventItem = eventRepository.GetById(editEventModel.Id); if (eventItem == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Group post with id = " + editEventModel.Id.ToString() + "not found")); } else { eventItem.Title = editEventModel.Title; eventItem.Description = editEventModel.Description; eventItem.TimeForEvent = editEventModel.TimeForEvent; eventItem.Location = editEventModel.Location; eventItem.Picture = editEventModel.Picture; eventRepository.SaveChanges(eventItem); return(Request.CreateResponse(HttpStatusCode.OK)); } }
public ActionResult EditPost(EditEventModel m, string eventName, string letter) { var model = CreateModel(eventName, letter); if (ModelState.IsValid) { var oldUrl = model.Event.UrlName; var newUrl = EntityNameHelper.CreateUrl(m.Event.Name); var eventModel = m.Event; eventModel.EventId = model.Event.EventId; //eventModel.UrlName = newUrl; DataRepository.UpdateEvent(eventModel); if (model.Event.Date >= DateTime.Now && model.Event.Bands.Any()) { // for each band on the event model.Event.Bands.ToList().ForEach(b => { DataRepository.AddFeedItem("Event page for {0} has been updated.", 3, b.Band.BandId, eventId: model.Event.EventId); }); } // send notification, adding the list of bands for the event Notifications.SendEventNotifications(NotificationType.NotifyEventUpdated, model.Event.EventId, new EventMessageData { Event = m.Event.Name, Link = model.Event.UrlName, Bands = model.Event.Bands.Select(b => b.Band.Name).ToString("<br />") }); //if (oldUrl != newUrl) //{ // return JsonValidationResult(ModelState, Url.RouteUrl("myevents", new { action = "edit", eventName = newUrl })); //} } return(JsonValidationResult(ModelState)); }
public ActionResult Edit(EditEventModel editModel) { var oldEvent = GetEvent(editModel.Id); var editEvent = new EditEventView(); var evt = MapEditEventModel(oldEvent, editModel); if (oldEvent.Number != editModel.Number) { evt.NumberSid = _service.ProcureNumber(evt.Number); ReleaseOldNumber(editModel); } using (var trans = _session.BeginTransaction()) { _session.Update(evt); trans.Commit(); } ViewData["timezone"] = _timezoneHydration.GetAndSetSelectedTimezone(evt.Timezone); editEvent.Message = "The event has been updated."; editEvent.Event = ConvertToEventJsonView(evt); return(View(editEvent)); }
public EditEventUnitTest() { mockRepo = new Mock <IEventRepository>(); editmodel = new EditEventModel(mockRepo.Object); }