private Bycicle ToBycicle(BycicleView bycicleView, string image) { return(new Bycicle { BycicleId = bycicleView.BycicleId, Description = bycicleView.Description, ImagePath = image, IsAvailable = bycicleView.IsAvailable, Latitude = bycicleView.Latitude, Longitude = bycicleView.Longitude, Street = bycicleView.Street, University = bycicleView.University, }); }
public async Task <ActionResult> Edit(BycicleView bycicleView) { if (ModelState.IsValid) { var pic = bycicleView.ImagePath; var folder = "~/Content/Bycicles"; if (bycicleView.ImageFile != null) { pic = FilesHelper.UploadPhoto(bycicleView.ImageFile, folder); pic = $"{folder}/{pic}"; } var bycicle = this.ToBycicle(bycicleView, pic); db.Entry(bycicle).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(bycicleView)); }
public async Task BycicleEditAsync() { // Arrange ByciclesController controller = new ByciclesController(); BycicleView item = new BycicleView() { BycicleId = 999, Street = "Title 1", University = "univerity 1", Description = "description 1", Latitude = "232", Longitude = "223", IsAvailable = false }; // Act ActionResult result = await controller.Edit(item); // Assert Assert.IsNotNull(result); }
public async Task <ActionResult> Create(BycicleView bycicleView) { if (ModelState.IsValid) { var pic = string.Empty; var folder = "~/Content/Bycicles"; if (bycicleView.ImageFile != null) { pic = FilesHelper.UploadPhoto(bycicleView.ImageFile, folder); pic = $"{folder}/{pic}"; } var bycicle = this.ToBycicle(bycicleView, pic); db.Bycicles.Add(bycicle); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(bycicleView)); }