public IActionResult UpdatePostDetail([FromBody] PostDetailCreateModel model) { var res = _postDetailService.UpdatePostDetail(model); if (res == 0) { return(ErrorBaseResponse(System.Net.HttpStatusCode.NoContent)); } return(OkBaseResponse(res)); }
public long UpdatePostDetail(PostDetailCreateModel model) { try { var entity = _dbCMSContext.PostDetails.Find(model.Id); if (entity == null || entity.Deleted) { throw new ArgumentNullException("Post detail"); } int oldFileStreamId = entity.FileStreamFid; entity = _mapper.Map(model, entity); entity.UniqueId = entity.UniqueId ?? UniqueIDHelper.GenerateRandomString(UNIQUE_ID_LENGTH); entity.LastModifiedDate = DateTime.Now; entity.LastModifiedBy = _workContext.UserGuid; _dbCMSContext.SaveChanges(); if (entity.Id > 0) { if (model.FileStreamFid > 0 && oldFileStreamId != model.FileStreamFid) { #region Insert new post file stream entity.FileTypeFid = (int)FileTypeEnum.Image; var fileStreamModel = PreparingPostFileStreamCreateModel(entity, PostFileCategoryEnum.Thumbnail); _postFileStreamService.CreatePostFileStream(fileStreamModel); _postFileStreamService.DeletePostFileStream(oldFileStreamId); #endregion } if (model.FileDescriptionIds.Count > 0) { foreach (var id in model.FileDescriptionIds) { var item = PreparingPostFileStreamCreateModel(entity, PostFileCategoryEnum.Detail); item.FileStreamFid = id; _postFileStreamService.CreatePostFileStream(item); } } var havePostDetailActive = _dbCMSContext.PostDetails.Count(x => x.PostFid == entity.PostFid && x.IsActivated) > 0; var post = _dbCMSContext.Posts.Find(entity.PostFid); post.IsActivated = havePostDetailActive; post.LastModifiedBy = _workContext.UserGuid; post.LastModifiedDate = DateTime.Now; _dbCMSContext.SaveChanges(); } return(entity.Id); } catch (Exception ex) { AQException.ThrowException(ex); return(0); } }
public long CreatePostDetail(PostDetailCreateModel model) { try { var existsPost = GetPostDetailByPostIdAndLanguageId(model.PostFid, model.LanguageFid); if (existsPost != null) { throw new ArgumentNullException($"Post is existing with language={model.LanguageFid} and postId={model.PostFid}"); } var entity = _mapper.Map <PostDetails>(model); entity.UniqueId = UniqueIDHelper.GenerateRandomString(UNIQUE_ID_LENGTH); entity.LastModifiedDate = DateTime.Now; entity.LastModifiedBy = _workContext.UserGuid; entity.Deleted = false; _dbCMSContext.PostDetails.Add(entity); _dbCMSContext.SaveChanges(); if (entity.Id > 0) { if (model.FileStreamFid > 0) { entity.FileTypeFid = (int)FileTypeEnum.Image; var fileStreamModel = PreparingPostFileStreamCreateModel(entity, PostFileCategoryEnum.Thumbnail); _postFileStreamService.CreatePostFileStream(fileStreamModel); } if (model.FileDescriptionIds.Count > 0) { foreach (var id in model.FileDescriptionIds) { var item = PreparingPostFileStreamCreateModel(entity, PostFileCategoryEnum.Detail); item.FileStreamFid = id; _postFileStreamService.CreatePostFileStream(item); } } } return(entity.Id); } catch (Exception ex) { AQException.ThrowException(ex); return(0); } }
public async Task <BaseResponse <long> > CreateNewPostDetail(PostDetailCreateModel model) { try { var req = new BaseRequest <PostDetailCreateModel>(model); var res = await _aPIExcute.PostData <long, PostDetailCreateModel>( url : $"{_baseAdminAPIUrl}{_adminPortalApiUrl.PostAPI.PostDetail}", requestParams : req, token : Token); if (res.IsSuccessStatusCode) { return(res); } return(null); } catch (Exception ex) { return(BaseResponse <long> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } }
public PostCreateModel() { postDetail = new PostDetailCreateModel(); postFileStream = new List <PostFileStreamCreateModel>(); }
public PostCreateViewModel() { PostInfo = new PostCreateModel(); PostDetail = new PostDetailCreateModel(); ListImgDescriptions = new List <string>(); }