Ejemplo n.º 1
0
        public async Task AddComplaintAsync(UserComplaintViewModel model, ClaimsPrincipal user)
        {
            Complaint complaint = null;

            var currentUser = await this.userManager.GetUserAsync(user);

            if (currentUser == null)
            {
                this.logger.LogWarning(ErrorMessages.UnableToLoadUser);
                throw new ApplicationException(ErrorMessages.UnableToLoadUser);
            }

            try
            {
                complaint = this.mapper.Map <Complaint>(model);

                complaint.FastFoodUserId = currentUser.Id;
                complaint.RestaurantId   = int.Parse(model.RestaurantId);

                await this.complaintRepository.AddAsync(complaint);

                await this.complaintRepository.SaveChangesAsync();

                this.logger.LogInformation(string.Format(LogMessages.UserAddedComplaint, currentUser.Id));
            }
            catch (Exception e)
            {
                throw new ApplicationException(e.Message);
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Complaint(UserComplaintViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = this.User;
                await this.userService.AddComplaintAsync(model, user);

                TempData[TempDataKeys.TempDataSuccessComplaintKey] = SuccessMessages.ComplaintSuccessMessage;
            }

            return(this.View());
        }