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 IActionResult CreateNewPostFileStream([FromBody] PostFileStreamCreateModel model) { var res = _postFileStreamService.CreatePostFileStream(model); if (res == 0) { return(ErrorBaseResponse(System.Net.HttpStatusCode.NotFound)); } return(OkBaseResponse(res)); }