public async Task <ActionResult> Create(ComplaintsDto Data) { var department = await _complaintsOptionsRepository.GetAsync(Data.ComplaintsOptionsId); Data.DepartmentsId = department.Data.DepartmentsId.GetValueOrDefault(); var options = await _complaintsOptionsRepository.GetAllAsync(); ViewBag.ComplaintsOptions = options.Data.Select(e => new SelectListItem { Value = e.Id.ToString(), Text = e.Name }).ToList(); var products = await _productsRepository.GetAllAsync(); ViewBag.Products = products.Data.Select(e => new SelectListItem { Value = e.Id.ToString(), Text = e.Name }).ToList(); var customers = await _customeRepository.GetAllAsync(); ViewBag.Customers = customers.Data.Select(e => new SelectListItem { Value = e.Id.ToString(), Text = $"{e.Name} {e.LastName} ({e.Email})" }).ToList(); var ticketTypes = await _ticketTypesRepository.GetAllAsync(); ViewBag.TicketTypes = ticketTypes.Data.Select(e => new SelectListItem { Value = e.Id.ToString(), Text = e.Description }).ToList(); var status1 = await _statusRepository.GetByNameAsync(StatusName.COMMITED); Data.StatusId = status1.Data.Id; var result = await _complaintsRepository.SaveAsync(Data); if (result.Success) { var ticketType = await _ticketTypesRepository.GetAsync(Data.TicketTypesId); var binnacle1 = new BinnacleDto { ApplicationUserId = User.Identity.GetUserId(), StatusId = Data.StatusId, Comment = $"La {ticketType.Data.Description} se ha creado con el estado: {StatusName.COMMITED}", ComplaintsId = result.Data.Id }; await _binnaclesRepository.SaveAsync(binnacle1); var deparment = await _departmentsRepository.GetAsync(Data.DepartmentsId); if (deparment.Success && deparment.Data != null) { var status2 = await _statusRepository.GetByNameAsync(StatusName.TRANSFERRED); await _complaintsRepository.UpdateStatusAsync(status2.Data.Id, result.Data.Id); var binnacle2 = new BinnacleDto { ApplicationUserId = User.Identity.GetUserId(), StatusId = status2.Data.Id, Comment = $"La {ticketType.Data.Description} ha sido transferido al departamento: {deparment.Data.Name}", ComplaintsId = result.Data.Id }; await _binnaclesRepository.SaveAsync(binnacle2); } } return(View(result)); }