public async Task <OperationResult> Create(Article_Dto model) { var item = await GetArticleByID(model.Article_Cate_ID, model.Article_ID); var data = _mapper.Map <Article>(model); try { if (item == null) { _articleRepository.Add(data); await _articleRepository.Save(); operationResult = new OperationResult { Success = true, Message = "Article was successfully added." }; } else { operationResult = new OperationResult { Success = true, Message = "Article was exists." }; } } catch (System.Exception ex) { operationResult = new OperationResult { Success = true, Message = ex.ToString() }; } return(operationResult); }
public async Task <IActionResult> Update(Article_Dto model) { model.Update_By = User.FindFirst(ClaimTypes.Name).Value; model.Update_Time = DateTime.Now; var data = await _articleService.Update(model); return(Ok(data)); }
public async Task <IActionResult> ChangeStatus(Article_Dto model) { model.Update_By = User.FindFirst(ClaimTypes.Name).Value; model.Update_Time = DateTime.Now; model.Status = !model.Status; var result = await _articleService.Update(model); if (result.Success) { await _hubContext.Clients.All.LoadDataArticle(); } return(Ok(result)); }
public async Task <IActionResult> Update([FromForm] Article_Dto model) { model.Content = model.Content == "null" ? null : model.Content; // Delete images, videos old var images = await _articleRepository.FindAll(x => x.Article_Cate_ID == model.Article_Cate_ID && x.Article_ID == model.Article_ID && x.Article_Name == model.Article_Name).Select(x => x.FileImages).Distinct().FirstOrDefaultAsync(); var videos = await _articleRepository.FindAll(x => x.Article_Cate_ID == model.Article_Cate_ID && x.Article_ID == model.Article_ID && x.Article_Name == model.Article_Name).Select(x => x.FileVideos).Distinct().FirstOrDefaultAsync(); if (!string.IsNullOrEmpty(images)) { _dropzoneService.DeleteFileUpload(images, "\\uploaded\\images\\article"); } if (!string.IsNullOrEmpty(videos)) { _dropzoneService.DeleteFileUpload(videos, "\\uploaded\\video\\article"); } // Add images, videos model.FileImages = null; model.FileVideos = null; if (model.Images != null) { model.FileImages = await _dropzoneService.UploadFiles(model.Images, model.Article_Cate_ID + "_" + model.Article_ID + "_", "\\uploaded\\images\\article"); } if (model.Videos != null) { model.FileVideos = await _dropzoneService.UploadFiles(model.Videos, model.Article_Cate_ID + "_" + model.Article_ID + "_", "\\uploaded\\video\\article"); } model.Update_By = User.FindFirst(ClaimTypes.Name).Value; model.Update_Time = DateTime.Now; var result = await _articleService.Update(model); if (result.Success) { await _hubContext.Clients.All.LoadDataArticle(); } return(Ok(result)); }
public async Task <IActionResult> Create([FromForm] Article_Dto model) { if (model.Images != null) { model.FileImages = await _dropzoneService.UploadFiles(model.Images, model.Article_Cate_ID + "_" + model.Article_ID + "_", "\\uploaded\\images\\article"); } if (model.Videos != null) { model.FileVideos = await _dropzoneService.UploadFiles(model.Videos, model.Article_Cate_ID + "_" + model.Article_ID + "_", "\\uploaded\\video\\article"); } model.Update_By = User.FindFirst(ClaimTypes.Name).Value; model.Update_Time = DateTime.Now; model.Content = model.Content == "null" ? null : model.Content; var result = await _articleService.Create(model); if (result.Success) { await _hubContext.Clients.All.LoadDataArticle(); } return(Ok(result)); }
public async Task <OperationResult> Update(Article_Dto model) { var data = _mapper.Map <Article>(model); try { _articleRepository.Update(data); await _articleRepository.Save(); operationResult = new OperationResult { Success = true, Message = "Article was successfully updated." }; } catch (System.Exception ex) { operationResult = new OperationResult { Success = true, Message = ex.ToString() }; } return(operationResult); }