Ejemplo n.º 1
0
        public async Task <CommentModel> Add(Guid couponId, CreateCommentModel model)
        {
            model.UserId = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "userId").Value);
            var comment = _mapper.Map <Comment>(model);
            var coupon  = await _repository.GetById(couponId);

            coupon.AddComment(comment);

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

            return(_mapper.Map <CommentModel>(comment));
        }
Ejemplo n.º 2
0
        public async Task <PhotoModel> Add(Guid couponId, CreatePhotoModel model)
        {
            var userId = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "userId").Value);
            var coupon = await _repository.GetById(couponId);

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

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

            coupon.AddPhoto(photo);

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

            return(_mapper.Map <PhotoModel>(photo));
        }
Ejemplo n.º 3
0
        public async Task Update(Guid id, UpdateCouponModel model)
        {
            var coupon = await _couponRepository.GetById(id);

            coupon.Update(model.Name, model.Category, model.ExpirationDate, model.Description);

            _couponRepository.Update(coupon);
            await _couponRepository.SaveChanges();
        }