Beispiel #1
0
        public async Task <ServicioResponse> DeleteAsync(int id)
        {
            var existingServicio = await _servicioRepository.FindFirstByConditionAsync(u => u.ID == id);

            if (existingServicio == null)
            {
                return(new ServicioResponse("User not found"));
            }
            try
            {
                _servicioRepository.Remove(existingServicio);
                await _unitOfWork.CompleteAsync();

                return(new ServicioResponse(existingServicio));
            }
            catch (Exception ex)
            {
                return(new ServicioResponse($"An error occurred when deleting the servicio: {ex.Message}"));
            }
        }
Beispiel #2
0
        public async Task <CommentResponse> CreateAsync(Comment comment)
        {
            try
            {
                _commentRepository.Add(comment);

                var servicio = await _servicioRepository.FindFirstByConditionAsync(s => s.ID == comment.ServicioID);

                if (servicio != null)
                {
                    servicio.UpdateAverages(comment.RatingFood, comment.RatingService);
                    _servicioRepository.Update(servicio);
                }

                await _unitOfWork.CompleteAsync();

                return(new CommentResponse(comment));
            }
            catch (Exception ex)
            {
                return(new CommentResponse($"There was an error creating the comment: {ex.Message}"));
            }
        }