public void FromValidModel_DbEventPropertiesAreChanged() { var dbEvent = this.db.Events.Find(1); var id = dbEvent.Id; var oldCode = dbEvent.Code; var oldTitle = dbEvent.Title; var existingEventModel = new EventSetupModel() { Id = 1, Code = "007", Title = "Seventh" }; var userId = "ABC"; this.service.SaveEventChanges(existingEventModel, userId); var savedEvent = this.db.Events.Find(1); Assert.AreEqual(id, savedEvent.Id); Assert.AreNotEqual(oldCode, savedEvent.Code); Assert.AreNotEqual(oldTitle, savedEvent.Title); }
public async Task <IActionResult> SetupEvent(EventSetupModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var userId = await this.GetCurrentUserId(); var dbEvent = this.service.GetEvent(model, userId); if (dbEvent == null) { return(LocalRedirect("/manager/activities/index")); } var isSaved = this.service.SaveEventChanges(model, dbEvent); if (isSaved) { return(LocalRedirect("/manager/activities/index")); } ViewData["Msg"] = "Event Code is occupied"; return(this.View(model)); }
public void SaveValidModel_ReturnsTrue() { var existingEventModel = new EventSetupModel() { Id = 1, Code = "007", Title = "Seventh", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(7) }; var userId = "ABC"; var isSaved = this.service.SaveEventChanges(existingEventModel, userId); Assert.AreEqual(true, isSaved); }
public bool SaveEventChanges(EventSetupModel model, Event dbEvent) { if (dbEvent.Code != model.Code) { var codeIsOccupied = this.db.Events.Any(e => e.Code == model.Code && e.IsDeleted == false); if (codeIsOccupied) { return(false); } } dbEvent.Code = model.Code; dbEvent.Title = model.Title; dbEvent.StartDate = model.StartDate; dbEvent.EndDate = model.EndDate; dbEvent.IsClosed = model.IsClosed; dbEvent.IsModerated = model.IsModerated; dbEvent.AnonymousAllowed = model.AnonymousAllowed; db.SaveChanges(); return(true); }
public Event GetEvent(EventSetupModel model, string userId) { var dbEvent = this.GetDbEvent(model.Id, userId); return(dbEvent); }