public DepartmentImageViewModel Save(DepartmentImageViewModel model) { var obj = model.GetDepartmentImagesEntity(); if (obj.Id > 0) { _iRepository.Update(obj); } else { _iRepository.Insert(obj); model.Id = obj.Id; } return(model); }
public ActionResult AddEdit(DepartmentViewModel model, IEnumerable <HttpPostedFileBase> files, string create = null) { try { if (model == null || !ModelState.IsValid) { return(View(model)); } model = _service.Save(model); _cacheManager.Remove(CacheKeys.DepartmentList.ToString()); if (files != null) { foreach (HttpPostedFileBase file in files) { DepartmentImageViewModel modelfile = new DepartmentImageViewModel(); modelfile.DepartmentId = model.DepartmentId; modelfile.ImageName = UploadFile(file); _imageService.Save(modelfile); } } SuccessNotification(Resources.SaveSuccess); if (string.IsNullOrEmpty(create)) { return(RedirectToAction(nameof(Index))); } return(create.Equals("Save & Continue") ? RedirectToAction(nameof(AddEdit), new { id = model.DepartmentId }) : RedirectToAction(nameof(Index))); } catch (Exception e) { Logger.log.Error($"Doctors > KendoSave. Error: {e.Message}"); ErrorNotification(Resources.SaveFailed); return(View(model)); } }
public ActionResult KendoDestroyImage([DataSourceRequest] DataSourceRequest request, DepartmentImageViewModel model) { try { _imageService.Delete(model.Id); _cacheManager.Remove(CacheKeys.DepartmentList.ToString()); return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); } catch (Exception ex) { Logger.log.Error($"DepartmentImage > KendoDestroy. Error: {ex.Message}"); return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); } }