Beispiel #1
0
 /// <summary>
 /// Mapping User Activity Log DTO to Action
 /// </summary>
 /// <param name=></param>
 /// <param name=></param>
 /// <returns></returns>
 public Post MappingPostupdateDTOToPost(Post post, PostUpdateDTO PostUpdateDTO)
 {
     #region Declare Return Var with Intial Value
     Post Post = post;
     #endregion
     try
     {
         if (PostUpdateDTO.PostId > default(int))
         {
             Post.PostId            = PostUpdateDTO.PostId;
             Post.YearsOfExperience = PostUpdateDTO.YearsOfExperience;
             Post.AddationalSalary  = PostUpdateDTO.AddationalSalary;
             Post.Area              = PostUpdateDTO.Area;
             Post.CareerLevelId     = PostUpdateDTO.CareerLevelId;
             Post.IsClosed          = PostUpdateDTO.IsClosed;
             Post.IsHideSalary      = PostUpdateDTO.IsHideSalary;
             Post.NumberOfVacancies = PostUpdateDTO.NumberOfVacancies;
             Post.PostDescription   = PostUpdateDTO.PostDescription;
             Post.PostLocationId    = PostUpdateDTO.PostLocationId;
             Post.PostTypeId        = PostUpdateDTO.PostTypeId;
             Post.SalaryFrom        = PostUpdateDTO.SalaryFrom;
             Post.SalaryTo          = PostUpdateDTO.SalaryTo;
         }
     }
     catch (Exception exception) { }
     return(Post);
 }
Beispiel #2
0
        public IActionResult UpdatePost([FromBody] PostUpdateDTO postUpdateDTO)
        {
            if (postUpdateDTO == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (this._unitOfWork.PostRepository.Find(postUpdateDTO.Id) == null)
            {
                return(NotFound());
            }

            var post = this._mapper.Map <Post>(postUpdateDTO);

            // Insert tag from list tag id
            PostUtilities.InsertTagsInPost(this._unitOfWork, post, postUpdateDTO.TagsGuid);
            // Insert tag from list tag id
            PostUtilities.InsertCommentsInPost(this._unitOfWork, post, postUpdateDTO.CommentsGuid);

            this._unitOfWork.PostRepository.Update(post);
            if (this._unitOfWork.SaveChanges() == 0)
            {
                ModelState.AddModelError("error", $"Something went wrong");
                return(StatusCode(StatusCodes.Status500InternalServerError, ModelState));
            }

            return(NoContent());
        }
Beispiel #3
0
 public static void setPostUpdateFields(this Post post, PostUpdateDTO postDTO)
 {
     post.Updated = DateTime.Now;
     post.Content = postDTO.Content;
     post.Deleted = postDTO.Deleted;
     post.Excerpt = postDTO.Excerpt;
     post.Title   = postDTO.Title;
 }
Beispiel #4
0
        public async Task <IActionResult> UpdatePost(PostUpdateDTO postUpdateDto)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string userName = User.Identity.Name;

                    var user = await _userManager.FindByNameAsync(userName);

                    var userViewDTO = _mapper.Map <UserViewDto>(user);

                    if (postUpdateDto.NewPictures != null)
                    {
                        List <Picture> pictures = AddFiles(postUpdateDto.NewPictures, postUpdateDto.Id, userName);

                        foreach (var picture in pictures)
                        {
                            await _pictureService.CreateAsync(picture);
                        }
                    }

                    if (postUpdateDto.PictureViewDTOs != null)
                    {
                        foreach (var picture in postUpdateDto.PictureViewDTOs)
                        {
                            if (picture.Delete == true)
                            {
                                System.IO.File.Delete(picture.Path);

                                await _pictureService.DeleteAsync(picture.Id);
                            }
                        }
                    }

                    postUpdateDto.Modified   = DateTime.Now;
                    postUpdateDto.ModifiedBy = userName;

                    var postToUpdate = _mapper.Map <Post>(postUpdateDto);

                    await _postService.UpdateEntryAsync(postToUpdate);
                }
                catch (DbUpdateException ex)
                {
                    return(Content(ex.Message));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(View(postUpdateDto));
        }
Beispiel #5
0
 public static Post PostUpdateDTOToPost(PostUpdateDTO p)
 {
     return(new Post
     {
         Created = DateTime.Now,
         AuthorId = Helper.IsNumeric(p.AuthorId)?p.AuthorId : -1,
         Content = p.Content,
         Deleted = false,
         Excerpt = p.Excerpt,
         Title = p.Title,
         Public = true
     });
 }
Beispiel #6
0
 /// <summary>
 /// Updae Post AppService
 /// </summary>
 /// <returns>bool<bool></returns>
 public async Task <bool> UpdatePost(PostUpdateDTO postUpdateDTO)
 {
     #region Declare a return type with initial value.
     bool isUpdated = false;
     #endregion
     try
     {
         if (postUpdateDTO != null)
         {
             isUpdated = await PostBusinessMapping.UpdatePost(postUpdateDTO);
         }
     }
     catch (Exception exception) {}
     return(isUpdated);
 }
Beispiel #7
0
        public async Task <IActionResult> Posts(int id, PostUpdateDTO postUpdateDTO)
        {
            if (postUpdateDTO == null)
            {
                return(BadRequest());
            }

            var postFromDB = await _postRepo.GetAll().FirstOrDefaultAsync(x => x.PostId == id);

            int userid = Convert.ToInt32(User.Claims.Where(x => x.Type == "UserId").FirstOrDefault()?.Value);

            //check if is the same owner
            if (postFromDB.AuthorId != userid)
            {
                return(Unauthorized("your'e not authorized to update this post"));
            }
            if (postFromDB == null)
            {
                return(NotFound());
            }

            //the function setPostUpdateFields is in mapper class.
            postFromDB.setPostUpdateFields(postUpdateDTO);

            _postRepo.Update(postFromDB);
            try
            {
                if (await _postRepo.SaveAll())
                {
                    return(NoContent());
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                var x = ex.Message;
            }
            return(BadRequest());
        }
Beispiel #8
0
        public async Task <IActionResult> UpdatePost(int id, [FromBody] PostUpdateDTO post)
        {
            try
            {
                var postFromDb = await _repo.GetOneWithConditionTracking <Post>(post => post.Id == id);

                if (postFromDb == null)
                {
                    return(NotFound());
                }
                _mapper.Map(post, postFromDb);
                if (await _repo.SaveAll())
                {
                    return(Ok());
                }
                return(NoContent());
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }
        /// <summary>
        /// Update User Action Activity Log
        /// </summary>
        /// <param name=></param>
        /// <returns>bool</returns>
        public async Task <bool> UpdatePost(PostUpdateDTO PostUpdateDTO)
        {
            #region Declare a return type with initial value.
            bool isPostUpdated = default(bool);
            #endregion
            try
            {
                if (PostUpdateDTO != null)
                {
                    #region Vars
                    Post Post = null;
                    #endregion
                    #region Get Activity By Id
                    Post = await UnitOfWork.PostRepository.GetById(PostUpdateDTO.PostId);

                    #endregion
                    if (Post != null)
                    {
                        #region  Mapping
                        Post = PostMapping.MappingPostupdateDTOToPost(Post, PostUpdateDTO);
                        #endregion
                        if (Post != null)
                        {
                            #region  Update Entity
                            UnitOfWork.PostRepository.Update(Post);
                            isPostUpdated = await UnitOfWork.Commit() > default(int);

                            #endregion
                        }
                    }
                }
            }
            catch (Exception exception)
            {
            }
            return(isPostUpdated);
        }
        public async Task <ActionResult <CommonAPIResponse <bool> > > UpdatePost(PostUpdateDTO PostUpdateDTO)
        {
            #region Declare return type with initial value.
            JsonResult jsonResult = GetDefaultJsonResult <bool>();
            #endregion

            try
            {
                #region Validate userUpdateDTO for nullability before prepaing the response.
                if (await PostAppService.UpdatePost(PostUpdateDTO))
                {
                    jsonResult = JsonResultResponse(CommonHelper.GetResponseMessage(APIResponseMessage.Success, CurrentLanguagId), true, HttpStatusCode.OK);
                }
                else
                {
                    jsonResult = JsonResultResponse(CommonHelper.GetResponseMessage(APIResponseMessage.InvalidCredentials, CurrentLanguagId), false, HttpStatusCode.BadRequest);
                }
                #endregion
            }
            catch (Exception exception)
            {
            }
            return(jsonResult);
        }