public ExhibitionDto Create(ExhibitionDto dto) { if (string.IsNullOrEmpty(dto.Name)) { throw new ArgumentNullException("Name"); } Exhibition exhibition = new Exhibition() { Name = dto.Name, Description = dto.Description, StartDate = dto.StartDate, FinishDate = dto.FinishDate, Organiser = dto.Organiser, Price_Adult = dto.Price_Adult, Price_Child = dto.Price_Child, Price_Concession = dto.Price_Concession, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow, IsDeleted = false }; if (dto.Image != null) { exhibition.Image = dto.Image; } Db.Exhibitions.Add(exhibition); Db.SaveChanges(); return(Mapper.Map <ExhibitionDto>(exhibition)); }
public ExhibitionDto Update(ExhibitionDto dto) { if (string.IsNullOrEmpty(dto.Name)) { throw new ArgumentNullException("Name"); } var exhibition = Db.Exhibitions.FirstOrDefault(m => m.Id == dto.Id); if (exhibition == null) { NotFoundException(); } exhibition.Name = dto.Name; exhibition.Description = dto.Description; exhibition.StartDate = dto.StartDate; exhibition.FinishDate = dto.FinishDate; exhibition.Organiser = dto.Organiser; exhibition.Price_Adult = dto.Price_Adult; exhibition.Price_Child = dto.Price_Child; exhibition.Price_Concession = dto.Price_Concession; exhibition.ModifiedDate = DateTime.UtcNow; if (dto.Image != null) { exhibition.Image = dto.Image; } Db.SaveChanges(); return(Mapper.Map <ExhibitionDto>(dto)); }
public void TestUpdate_NoImage() { //Get valid exhibition ExhibitionDto exhibition = GetExhibition(); exhibition.Name = "Test"; exhibition.Description = "Test"; exhibition.StartDate = DateTime.Now; exhibition.FinishDate = DateTime.Parse("01/01/2099"); exhibition.Price_Adult = 10; exhibition.Price_Child = 5; exhibition.Price_Concession = 7; exhibition.Organiser = "Test"; exhibition.Image = null; ExhibitionDto updatedExhibition = _controller.Update(exhibition); Assert.IsNotNull(updatedExhibition); Assert.IsNotNull(updatedExhibition.Id); Assert.AreEqual(exhibition.Id, updatedExhibition.Id); Assert.AreEqual(exhibition.Name, updatedExhibition.Name); Assert.AreEqual(exhibition.Description, updatedExhibition.Description); Assert.AreEqual(exhibition.StartDate, updatedExhibition.StartDate); Assert.AreEqual(exhibition.FinishDate, updatedExhibition.FinishDate); Assert.AreEqual(exhibition.Price_Adult, updatedExhibition.Price_Adult); Assert.AreEqual(exhibition.Price_Child, updatedExhibition.Price_Child); Assert.AreEqual(exhibition.Price_Concession, updatedExhibition.Price_Concession); Assert.AreEqual(exhibition.Organiser, updatedExhibition.Organiser); }
public void TestCreate_ShouldSucceed() { //Set up dto ExhibitionDto exhibition = new ExhibitionDto() { Name = "Test", Description = "Test", StartDate = DateTime.Now, FinishDate = DateTime.Parse("01/01/2099"), Price_Adult = 10, Price_Child = 5, Price_Concession = 7, Organiser = "Test", Image = testImage }; //Make test request ExhibitionDto exhibitionResult = _controller.Create(exhibition); //Assert Values Assert.IsNotNull(exhibitionResult); Assert.IsNotNull(exhibitionResult.Id); Assert.IsTrue(exhibitionResult.Id != 0); Assert.AreEqual(exhibition.Name, exhibitionResult.Name); Assert.AreEqual(exhibition.Description, exhibitionResult.Description); Assert.AreEqual(exhibition.StartDate, exhibitionResult.StartDate); Assert.AreEqual(exhibition.FinishDate, exhibitionResult.FinishDate); Assert.AreEqual(exhibition.Price_Adult, exhibitionResult.Price_Adult); Assert.AreEqual(exhibition.Price_Child, exhibitionResult.Price_Child); Assert.AreEqual(exhibition.Price_Concession, exhibitionResult.Price_Concession); Assert.AreEqual(exhibition.Organiser, exhibitionResult.Organiser); Assert.IsNotNull(exhibitionResult.CreatedDate); Assert.IsNotNull(exhibitionResult.ModifiedDate); }
public ExhibitionDto Update([FromBody] ExhibitionDto dto) { try { return(new ExhibitonHandler(isTest).Update(dto)); } catch (Exception ex) { throw; } }
public void TestGetById_ValidId() { //Get a valid exhibition ExhibitionDto validExhibition = GetExhibition(); //Try to get this exhibition ExhibitionDto exhibitionResult = _controller.GetById(validExhibition.Id); Assert.IsNotNull(exhibitionResult); Assert.IsNotNull(exhibitionResult.Id); Assert.AreEqual(validExhibition.Id, exhibitionResult.Id); }
public void TestGetFiltered_AllFilters() { //Create Exhibition for getfiltered validation ExhibitionDto validExhibition = CreateTestExhibition(); var results = _controller.GetFiltered(new ApiFilter() { isDeleted = false, numPerPage = 100, pageNumber = 0 }); Assert.IsNotNull(results); Assert.IsTrue(!results.Any(m => m.IsDeleted)); Assert.IsTrue(results.Count <= 100); Assert.IsTrue(results.Count == results.Distinct().Count()); }
// GET: Artefacts/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var request = new HTTPrequest(); ExhibitionDto exhibition = await request.Get <ExhibitionDto>("api/exhibition/" + id); if (exhibition == null) { return(HttpNotFound()); } return(View(exhibition)); }
public void TestUpdate_InvalidId() { //Get valid exhibition ExhibitionDto exhibition = GetExhibition(); ExhibitionDto updatedExhibition = new ExhibitionDto() { Id = 0, Name = exhibition.Name, Description = exhibition.Description, Image = exhibition.Image }; _controller.Update(updatedExhibition); }
public void TestCreate_NoStartDate() { //Set up dto ExhibitionDto exhibition = new ExhibitionDto() { Name = "Test", Description = "Test", FinishDate = DateTime.Parse("01/01/2099"), Price_Adult = 10, Price_Child = 5, Price_Concession = 7, Organiser = "Test", Image = testImage }; _controller.Create(exhibition); }
public void TestUpdate_EmptyName() { //Get valid exhibition ExhibitionDto exhibition = GetExhibition(); exhibition.Name = string.Empty; exhibition.Description = "Test"; exhibition.StartDate = DateTime.Now; exhibition.FinishDate = DateTime.Parse("01/01/2099"); exhibition.Price_Adult = 10; exhibition.Price_Child = 5; exhibition.Price_Concession = 7; exhibition.Organiser = "Test"; exhibition.Image = testImage; _controller.Update(exhibition); }
public void TestDelete_ValidId() { //Get valid exhibition ExhibitionDto validExhibition = GetExhibition(); //Delete exhibition bool result = _controller.Delete(validExhibition.Id); Assert.IsTrue(result); //Get exhibition for comparison ExhibitionDto exhibitionResult = _controller.GetById(validExhibition.Id); Assert.IsNotNull(exhibitionResult); Assert.IsNotNull(exhibitionResult.Id); Assert.AreEqual(validExhibition.Id, exhibitionResult.Id); Assert.IsTrue(exhibitionResult.IsDeleted); }
public void TestGetFiltered_IsDeleted() { //Create a exhibition to test on ExhibitionDto validExhibition = CreateTestExhibition(); //delete for test _controller.Delete(validExhibition.Id); var results = _controller.GetFiltered(new ApiFilter() { isDeleted = true, numPerPage = 100, pageNumber = 0 }); Assert.IsNotNull(results); Assert.IsTrue(!results.Any(m => !m.IsDeleted)); Assert.IsTrue(results.Count <= 100); Assert.IsTrue(results.Count == results.Distinct().Count()); }
ExhibitionDto CreateTestExhibition() { ExhibitionDto exhibition = new ExhibitionDto() { Name = "Test", Description = "Test", StartDate = DateTime.Now, FinishDate = DateTime.Parse("01/01/2099"), Price_Adult = 10, Price_Child = 5, Price_Concession = 7, Organiser = "Test", Image = null }; exhibition = _controller.Create(exhibition); return(exhibition); }
public async Task <ActionResult> Edit(ExhibitionDto exhibition, HttpPostedFileBase imageFile) { if (string.IsNullOrEmpty(exhibition.Name)) { ViewBag.ValidationName = "Name field is required."; return(View(exhibition)); } var request = new HTTPrequest(); ExhibitionDto exhibition_editted = await request.Get <ExhibitionDto>("api/exhibition/" + exhibition.Id); if (ModelState.IsValid) { exhibition_editted.Name = exhibition.Name; exhibition_editted.Description = exhibition.Description; exhibition_editted.Price_Adult = exhibition.Price_Adult; exhibition_editted.Price_Concession = exhibition.Price_Concession; exhibition_editted.Price_Child = exhibition.Price_Child; exhibition_editted.StartDate = exhibition.StartDate; exhibition_editted.FinishDate = exhibition.FinishDate; exhibition_editted.Organiser = exhibition.Organiser; exhibition_editted.ModifiedDate = DateTime.Now; // HttpPostedFileBase imgFile = Request.Files["ImageFile"]; if (imageFile != null) { exhibition_editted.Image = new byte[imageFile.ContentLength]; imageFile.InputStream.Read(exhibition_editted.Image, 0, imageFile.ContentLength); string fileExtension = Path.GetExtension(imageFile.FileName); //exhibition_editted.ImageFileType = fileExtension; } else { exhibition_editted.Image = exhibition_editted.Image; //exhibition_editted.ImageFileType = exhibition_editted.ImageFileType; } await request.Put <ExhibitionDto>("api/exhibition", exhibition_editted); return(RedirectToAction("Index", new { recentAction = "Editted", recentName = exhibition.Name, recentId = exhibition.Id })); } return(View(exhibition)); }
public async Task <ActionResult> Create(ExhibitionDto exhibition, HttpPostedFileBase imageFile) { if (string.IsNullOrEmpty(exhibition.Name)) { ViewBag.ValidationName = "Name field is required."; return(View(exhibition)); } ExhibitionDto newExhibition = new ExhibitionDto(); newExhibition.Id = exhibition.Id; newExhibition.Name = exhibition.Name; newExhibition.Description = exhibition.Description; newExhibition.ModifiedDate = exhibition.ModifiedDate; newExhibition.StartDate = exhibition.StartDate; newExhibition.FinishDate = exhibition.FinishDate; newExhibition.Price_Adult = exhibition.Price_Adult; newExhibition.Price_Concession = exhibition.Price_Concession; newExhibition.Price_Child = exhibition.Price_Child; if (ModelState.IsValid) { var request = new HTTPrequest(); HttpPostedFileBase imgFile = Request.Files["ImageFile"]; if (imgFile != null) { exhibition.Image = new byte[imgFile.ContentLength]; imgFile.InputStream.Read(exhibition.Image, 0, imgFile.ContentLength); string fileExtension = Path.GetExtension(imgFile.FileName); //exhibition.ImageFileType = fileExtension; } exhibition = await request.Post <ExhibitionDto>("api/exhibition", exhibition); return(RedirectToAction("Index", new { recentAction = "Created", recentName = exhibition.Name, recentId = exhibition.Id })); } else { return(View()); } }
public void TestCreate_NoImage() { //Set up dto ExhibitionDto exhibition = new ExhibitionDto() { Name = "Test", Description = "Test", StartDate = DateTime.Now, FinishDate = DateTime.Parse("01/01/2099"), Price_Adult = 10, Price_Child = 5, Price_Concession = 7, Organiser = "Test", Image = null }; //Make test request ExhibitionDto exhibitionResult = _controller.Create(exhibition); //Assert Values Assert.IsNotNull(exhibitionResult); Assert.IsNotNull(exhibitionResult.Id); Assert.IsTrue(exhibitionResult.Id != 0); }
public async Task <ActionResult> DeleteConfirmed(int id) { var request = new HTTPrequest(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ExhibitionDto exhibition = await request.Get <ExhibitionDto>("api/exhibition/" + id); if (exhibition == null) { return(HttpNotFound()); } exhibition.IsDeleted = true; var requestDelete = new HTTPrequest(); exhibition = await requestDelete.Put <ExhibitionDto>("api/exhibition", exhibition); await request.Delete("api/exhibition/" + id.ToString()); return(RedirectToAction("Index", new { recentAction = "Deleted", recentName = exhibition.Name, recentId = exhibition.Id })); }