public JsonResult GetStoneDetail(int stoneId) { Stone stone = StoneDbModel.GetStoneModel(stoneId); StoneViewModel stoneviewModel = helper.GetViewModelFromDbStone(stone); return(Json(stoneviewModel, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveStone(StoneViewModel stoneViewModel) { string message = ""; try { if (stoneViewModel != null) { Stone stone = helper.GetStoneObjectFromViewModelStone(stoneViewModel); if (stone != null) { if (stone.StoneId > 0) { message = "Stone details updated successfully"; StoneDbModel.UpdateStone(stone); } else { message = "Stone created successfully"; StoneDbModel.SaveStone(stone); } } else { message = "Application was not able to create Stone, contact Admin"; } } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); message = ex.Message; } return(Json(new { UpdateMessage = message })); }
public Stone GetStoneObjectFromViewModelStone(StoneViewModel stoneViewModel) { Stone stone = new Stone(); stone.StoneId = stoneViewModel.StoneId; stone.StoneName = stoneViewModel.StoneName; stone.IsActive = stoneViewModel.IsActive; return(stone); }
public StoneViewModel GetViewModelFromDbStone(Stone stone) { StoneViewModel stoneViewModel = new StoneViewModel(); stoneViewModel.StoneId = stone.StoneId; stoneViewModel.StoneName = stone.StoneName; stoneViewModel.IsActive = stone.IsActive; return(stoneViewModel); }
public List <StoneViewModel> GetViewModelFromDbStoneCollection(List <Stone> stoneCollection) { if (stoneCollection == null || stoneCollection.Count == 0) { return(null); } List <StoneViewModel> stoneViewModelCollection = new List <ViewModel.Product.StoneViewModel>(); foreach (Stone stone in stoneCollection) { StoneViewModel stoneViewModel = GetViewModelFromDbStone(stone); if (stoneViewModel != null) { stoneViewModelCollection.Add(stoneViewModel); } } return(stoneViewModelCollection); }
public JsonResult Save(StoneViewModel model) { Response response; try { string oldFileName = ""; int status = 200; string message = string.Empty; using (var db = new KiaGalleryContext()) { if (string.IsNullOrEmpty(model.name)) { status = 500; message = "وارد کردن نام سنگ اجباری است."; } else { if (model.id != null && model.id > 0) { var entity = db.Stone.Single(x => x.Id == model.id); entity.Name = model.name.Trim(); entity.EnglishName = model.englishName.Trim(); entity.StoneType = model.stoneType; entity.Order = model.order; entity.FileName = model.fileName?.Trim(); entity.Active = model.active; entity.ModifyUserId = GetAuthenticatedUserId(); entity.ModifyDate = DateTime.Now; entity.Ip = Request.UserHostAddress; if (!string.IsNullOrEmpty(entity.FileName) && entity.FileName != model.fileName) { oldFileName = entity.FileName; } message = "سنگ با موفقیت ویرایش شد."; } else { var entity = new Stone() { Name = model.name.Trim(), EnglishName = model.englishName.Trim(), StoneType = model.stoneType, Order = model.order, FileName = model.fileName?.Trim(), Active = model.active, CreateUserId = GetAuthenticatedUserId(), ModifyUserId = GetAuthenticatedUserId(), CreateDate = DateTime.Now, ModifyDate = DateTime.Now, Ip = Request.UserHostAddress }; db.Stone.Add(entity); message = "سنگ با موفقیت ایجاد شد."; } db.SaveChanges(); if (!string.IsNullOrEmpty(oldFileName) && System.IO.File.Exists(Server.MapPath("~/Upload/Stone/" + oldFileName))) { System.IO.File.Delete(Server.MapPath("~/Upload/Stone/" + oldFileName)); } } } response = new Response() { status = status, message = message }; } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }