public ActionResult Create(ImageEditorViewModel model) { try { if (ModelState.IsValid) { BrunaContext db = new BrunaContext(); var fileModel = WebFileViewModel.getEntityModel(model.FileImage); db.WebFiles.Add(fileModel); db.SaveChanges(); var entity = ImageEditorViewModel.getEnityModel(model); entity.WebImageId = fileModel.Id; entity.OrderNo = db.Galleries.Count() > 0 ? db.Galleries.Max(x => x.OrderNo) + 1 : 1; db.Galleries.Add(entity); db.SaveChanges(); return(Json(new { success = true, Caption = model.Caption })); //ModelState.AddModelError("", "Uspešno ste naložili sliko."); //return RedirectToAction("Index", "Gallery"); } return(Json(new { success = false, ValidationMessage = "Please check validation messages" })); //ViewBag.errorMessage = "Prišlo je do napake."; //return View(); } catch (Exception) { return(Json(new { success = false, ExceptionMessage = "Some error here" })); } }
public ActionResult Create(ImageEditorViewModel model) { try { if (ModelState.IsValid) { ImageDBEntities db = new ImageDBEntities(); var fileModel = WebFileViewModel.getEntityModel(model.FileImage); db.WebFiles.Add(fileModel); db.SaveChanges(); var entity = ImageEditorViewModel.getEnityModel(model); entity.WebImageId = fileModel.Id; entity.OrderNo = db.Galleries.Count() > 0 ? db.Galleries.Max(x => x.OrderNo) + 1 : 1; db.Galleries.Add(entity); db.SaveChanges(); return(Json(new { success = true, Caption = model.Caption })); } return(Json(new { success = false, ValidationMessage = "Please check validation messages" })); } catch (Exception ex) { return(Json(new { success = false, ExceptionMessage = "Some error here" })); } }
public ActionResult Create(ImageEditorViewModel model) { try { if (ModelState.IsValid) { DefaultContext db = new DefaultContext(); var fileModel = WebFileViewModel.getEntityModel(model.FileImage, Server.MapPath("~/Uploads/")); fileModel.IsDefault = true; var entity = ImageEditorViewModel.getEnityModel(model); entity.Files = new List <WebFile>(); entity.Files.Add(fileModel); entity.CreatedDate = DateTime.UtcNow; db.Galleries.Add(entity); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); } catch (Exception ex) { return(RedirectToAction("Index")); } }
public ActionResult Create(ImageEditorViewModel model) { var galleryLists = from s in galleryService.LoadAll() select s; var webFileLists = from v in webFileService.LoadAll() select v; try { if (ModelState.IsValid) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <WebFileDTO, WebFilesVM>()).CreateMapper(); var fileModel = WebFileViewModel.getEntityModel(model.FileImage); var coach = mapper.Map <WebFileDTO>(fileModel); webFileService.Save(coach); var mapper3 = new MapperConfiguration(cfg => cfg.CreateMap <GalleryDTO, GalleriesVM>()).CreateMapper(); var entity = ImageEditorViewModel.getEnityModel(model); entity.WebImageId = webFileLists.Select(c => c.Id).LastOrDefault(); entity.OrderNo = galleryLists.Count() > 0 ? galleryLists.Max(x => x.OrderNo) + 1 : 1; // must be changed entity.post_like = 0; var coach3 = mapper3.Map <GalleryDTO>(entity); galleryService.Save(coach3); return(Json(new { success = true, Caption = model.Caption })); } return(Json(new { success = false, ValidationMessage = "Please check validation messages" })); } catch (Exception ex) { return(Json(new { success = false, ExceptionMessage = "Some error here" })); } }