public JsonResult Load(int id) { Response response; try { using (var db = new KiaGalleryContext()) { var item = db.InstagramPost.Where(x => x.Id == id).SingleOrDefault(); var data = new InstagramPostViewModel() { id = item.Id, title = item.Title, instagramPostType = item.InstagramPostType, dayCounter = item.DayCounter, publishDate = DateUtility.GetPersianDate(item.PublishDate), respite = item.Respite, fileId = item.FileId, fileName = item.FileName, }; response = new Response() { status = 200, data = data, }; } } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }
public JsonResult Save(InstagramPostViewModel model) { Response response; try { var date = DateUtility.GetDateTime(model.publishDate); DateTime dateTimeNow = DateTime.Today; if (date < dateTimeNow) { response = new Response() { status = 500, message = "شما قادر به انتخاب روزهای گذشته نیستید.", }; return(Json(response, JsonRequestBehavior.AllowGet)); } int status = 200; string message = string.Empty; using (var db = new KiaGalleryContext()) { int userId = GetAuthenticatedUserId(); if (model.id != null && model.id > 0) { var entity = db.InstagramPost.Single(x => x.Id == model.id); entity.Title = model.title; entity.Respite = model.respite; entity.DayCounter = model.dayCounter; entity.FileId = model.fileId; entity.FileName = model.fileName; entity.PublishDate = DateUtility.GetDateTime(model.publishDate); entity.InstagramPostType = model.instagramPostType; entity.ModifyUserId = userId; entity.ModifyDate = DateTime.Now; entity.Ip = Request.UserHostAddress; message = "عملیات با موفقیت ویرایش شد."; } else { var entity = new InstagramPost() { Title = model.title, Respite = model.respite, DayCounter = model.dayCounter, FileId = model.fileId, FileName = model.fileName, PublishDate = DateUtility.GetDateTime(model.publishDate), InstagramPostType = model.instagramPostType, CreateUserId = GetAuthenticatedUserId(), ModifyUserId = GetAuthenticatedUserId(), CreateDate = DateTime.Now, ModifyDate = DateTime.Now, Ip = Request.UserHostAddress, }; db.InstagramPost.Add(entity); message = "عملیت با موفقیت ایجاد شد."; } db.SaveChanges(); } response = new Response() { status = status, message = message }; } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }