public JsonResult DeleteInquiry(int id) { Response response; try { using (var db = new KiaGalleryContext()) { InquiryProduct inquiryProduct = db.InquiryProduct.Where(x => x.Id == id).Single(); if (!string.IsNullOrEmpty(inquiryProduct.FileName)) { string serverPath = Server.MapPath("~/Upload/InquiryProduct"); string fileName = Path.Combine(serverPath, inquiryProduct.FileName); if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } } db.InquiryProduct.Remove(inquiryProduct); response = new Response() { status = 200, message = "استعلام محصول با موفقیت حذف شد" }; } } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public JsonResult AddInquiry(AddInquiryProductViewModel model) { Response response; var user = GetAuthenticatedUser(); try { using (var db = new KiaGalleryContext()) { if (!string.IsNullOrEmpty(model.fileName)) { model.fileName = SaveInquiryImage(model.base64, model.fileName); } InquiryProduct inquiryProduct = new InquiryProduct() { ProductId = model.productId, BranchId = user.BranchId.GetValueOrDefault(), FileName = model.fileName, Comment = model.comment, CreateUserId = user.Id, ModifyUserId = user.Id, CreateDate = DateTime.Now, ModifyDate = DateTime.Now, Ip = Request.UserHostAddress }; db.InquiryProduct.Add(inquiryProduct); db.SaveChanges(); } response = new Response() { status = 200, message = "درخواست استعلام محصول ذخیره شد " }; } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(JsonRequestBehavior.AllowGet)); }