Exemplo n.º 1
0
        public async Task <ActionResult> Create(ServiceRateDto ServiceRate)
        {
            var serviceRateExists = await _serviceRateRepository.GetByComplaintsIdAsync(ServiceRate.ComplaintsId);

            if (serviceRateExists.Data == null)
            {
                var saved = await _serviceRateRepository.SaveAsync(ServiceRate);
            }
            else
            {
                serviceRateExists.Data.Rate = ServiceRate.Rate;
                var removedPreviousRate = await _serviceRateRepository.UpdateAsync(serviceRateExists.Data);
            }

            var complaints = await _complaintsRepository.GetAsync(ServiceRate.ComplaintsId);

            var binnacle = new BinnacleDto
            {
                ComplaintsId      = ServiceRate.ComplaintsId,
                StatusId          = complaints.Data.StatusId,
                Comment           = $"SE HA PUNTUADO EL TICKET COMO: {ServiceRate.Rate}",
                ApplicationUserId = User.Identity.GetUserId()
            };

            await _binnaclesRepository.SaveAsync(binnacle);

            return(RedirectToAction(nameof(ComplaintsController.Details), "Complaints", new { id = ServiceRate.ComplaintsId }));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Add(BinnacleDto binnacleDto)
        {
            var complaint = await _complaintsRepository.GetAsync(binnacleDto.ComplaintsId.GetValueOrDefault());

            var binnacle = new BinnacleDto
            {
                ApplicationUserId = User.Identity.GetUserId(),
                StatusId          = complaint.Data.StatusId,
                Comment           = binnacleDto.Comment.ToUpper(),
                ComplaintsId      = complaint.Data.Id
            };
            var binnacles = await _binnaclesRepository.SaveAsync(binnacle);

            return(Json(binnacles));
        }
        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));
        }