public ActionResult NewRoomType(NewRoomTypeViewModel model, HttpPostedFileBase ImageUrl) { try { if (ImageUrl != null) { //string dosyaAdi = "room" + model.RoomType.ID + ImageUrl.ContentType; model.RoomType.Image = ImageUrl.FileName; var path = Path.Combine("~/Images/Rooms/" + model.RoomType.Image); ImageUrl.SaveAs(Server.MapPath(path)); } _roomTypesManagement.AddOrUpdate(model.RoomType); this.SuccessMessage($"<b>{model.RoomType.Name}</b> has been saved!"); } catch (Exception e) { this.ErrorMessage($"<b>{model.RoomType.Name}</b> could not be saved! ({e.Message})"); } return(RedirectToAction("Index")); }
public ActionResult NewRoomType(int?id) { NewRoomTypeViewModel model = new NewRoomTypeViewModel(); model.RoomType = id == null ? new RoomTypes() : _roomTypesManagement.Get(r => r.ID == id); return(View(model)); }