Exemplo n.º 1
0
        public async Task <OfferCommentModel> Add(Guid offerId, CreateOfferCommentModel model)
        {
            model.UserId = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "userId").Value);
            var comment = _mapper.Map <OfferComment>(model);
            var offer   = await _repository.GetById(offerId);

            offer.AddComment(comment);

            _repository.Update(offer);
            await _repository.SaveChanges();

            return(_mapper.Map <OfferCommentModel>(comment));
        }
Exemplo n.º 2
0
        public StatusModel Update(Offer offer)
        {
            var response      = new StatusModel();
            var offerToModify = _offersRepository.GetById(offer.Id);

            if (offerToModify != null)
            {
                var checkIfExists = _offersRepository.CheckIfExists(null, offer.Title);

                if (checkIfExists)
                {
                    response.IsSuccessfull = false;
                    response.Message       = $"There is already an offer with title {offer.Title}";
                }
                else
                {
                    offerToModify.Title       = offer.Title;
                    offerToModify.ValidUntil  = offer.ValidUntil;
                    offerToModify.Description = offer.Description;
                    //offerToModify.DateModified = DateTime.Now;
                    //offerToModify.Slug = menuItem.Title.GenerateSlug();
                    _offersRepository.Update(offerToModify);
                    response.Message = $"The offer with ID {offerToModify.Id} has been successfully updated.";
                }
            }
            else
            {
                response.IsSuccessfull = false;
                response.Message       = $"There is no offer with ID {offer.Id}";
            }
            return(response);
        }
Exemplo n.º 3
0
        public async Task Update(Guid id, UpsertOfferModel model)
        {
            var offer = await _repository.GetById(id);

            offer.Update(model.Name, model.Description, model.Price, model.CategoryId);

            _repository.Update(offer);
            await _repository.SaveChanges();
        }
        public void Activate(int id)
        {
            var offer = _offersRepository.GetById(id);

            if (offer == null)
            {
                throw new ArgumentNullException();
            }

            offer.IsActive = true;
            _offersRepository.Update(offer);
            _offersRepository.SaveChanges();
        }
Exemplo n.º 5
0
        public async Task <PhotoModel> Add(Guid offerId, CreatePhotoModel model)
        {
            var offer = await _repository.GetById(offerId);

            using var stream = new MemoryStream();
            await model.Content.CopyToAsync(stream);

            var photo = new Photo(model.Content.FileName, stream.ToArray());

            offer.Photos.Add(photo);

            _repository.Update(offer);

            await _repository.SaveChanges();

            return(_mapper.Map <PhotoModel>(photo));
        }