public RatingConfirmationDto Update(Guid id, RatingCreateDto dto)
        {
            var ratingToUpdate = _context.Ratings.FirstOrDefault(e => e.Id == id);

            if (ratingToUpdate == null)
            {
                throw new BusinessException("Rating does not exist");
            }

            Item item = MockData.Items.FirstOrDefault(e => e.Id == dto.ItemId);
            User user = MockData.Users.FirstOrDefault(e => e.Id == dto.UserId);

            if (item == null || user == null)
            {
                throw new BusinessException("Does not exist");
            }

            ratingToUpdate.DateOfTrade       = dto.DateOfTrade;
            ratingToUpdate.RatingDescription = dto.RatingDescription;
            ratingToUpdate.ItemRating        = dto.ItemRating;
            ratingToUpdate.SellerRating      = dto.SellerRating;
            ratingToUpdate.UserId            = dto.UserId;
            ratingToUpdate.ItemId            = dto.ItemId;

            _context.SaveChanges();

            _logger.Log("Rating updated!");

            return(_mapper.Map <RatingConfirmationDto>(ratingToUpdate));
        }
        public RatingConfirmationDto Create(RatingCreateDto dto)
        {
            Item item = MockData.Items.FirstOrDefault(e => e.Id == dto.ItemId);
            User user = MockData.Users.FirstOrDefault(e => e.Id == dto.UserId);

            if (item == null || user == null)
            {
                throw new BusinessException("Does not exist");
            }

            Rating newRating = new Rating()
            {
                Id                = Guid.NewGuid(),
                DateOfTrade       = dto.DateOfTrade,
                RatingDescription = dto.RatingDescription,
                ItemRating        = dto.ItemRating,
                SellerRating      = dto.SellerRating,
                UserId            = dto.UserId,
                ItemId            = dto.ItemId
            };

            _context.Ratings.Add(newRating);

            _context.SaveChanges();

            _logger.Log("New Rating created!");

            return(_mapper.Map <RatingConfirmationDto>(newRating));
        }
Exemplo n.º 3
0
        public ActionResult <RatingDto> CreateCategory([FromBody] RatingCreateDto ratingCreateDto)
        {
            var rating = mapper.Map <Rating>(ratingCreateDto);

            repository.Create(rating);
            repository.SaveChanges();
            var ratingDto = mapper.Map <RatingDto>(rating);

            return(CreatedAtRoute(nameof(GetRatingById), new { ratingDto.Id }, ratingDto));
        }
Exemplo n.º 4
0
        public ActionResult UpdateRating(int id, RatingCreateDto ratingCreateDto)
        {
            var ratingFromRepo = repository.GetById(x => x.Id == id);

            if (ratingFromRepo == null)
            {
                return(NotFound());
            }
            mapper.Map(ratingCreateDto, ratingFromRepo.Result);
            repository.Update(ratingFromRepo.Result);
            repository.SaveChanges();
            return(NoContent());
        }
        public ActionResult Put(Guid id, RatingCreateDto dto)
        {
            var entity = _repository.Update(id, dto);

            return(Ok(entity));
        }
        public ActionResult PostCoorporate([FromBody] RatingCreateDto dto)
        {
            var entity = _repository.Create(dto);

            return(Ok(entity));
        }