public async Task <IActionResult> AddPostCategory(PostCategoryDto postCategoryDto) { try { var postCategory = _mapper.Map <PostCategory>(postCategoryDto); _postCategoryService.AddPostCategory(postCategory); await _unitOfWork.Save(); return(Ok(postCategory)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult AddPostCategory(PostCategoryViewModel model) { if (ModelState.IsValid) { var entity = _postCategoryService.AddPostCategory(model); if (entity.Id > 0) { return(RedirectToAction(nameof(PostCategoryController.Index), "PostCategory")); } else { ModelState.AddModelError(string.Empty, "Kayıt başarısız"); } } return(View()); }
// API den gelen verilerden seçilenlerin eklenmesi public ServiceStatus AddPostFromApi(string[] books) { var serviceStatus = new ServiceStatus(); var httpUser = _httpContextAccessor.HttpContext.User; var claims = int.Parse(httpUser.Claims.ToList().Where(x => x.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value); var postCategory = _postCategoryService.GetPostCategory("Kitap"); if (postCategory == null) { serviceStatus = _postCategoryService.AddPostCategory("Kitap"); postCategory = _postCategoryService.GetPostCategory("Kitap"); } foreach (var item in books) { var isTherePost = _postRepository.Get(x => x.Title == (item + "(Kitap)")); if (isTherePost == null) { var post = new Post(); post.Title = item + "(Kitap)"; post.CreateDate = DateTime.Now; post.UserId = claims; post.PostCategoryId = postCategory.Id; post.ViewCount = 1; _postRepository.Add(post); try { _postRepository.SaveChanges(); serviceStatus.Status = true; } catch (Exception) { throw; } } } return(serviceStatus); }