public async Task <IActionResult> Create(ComplaintModel model)
        {
            if (ModelState.IsValid)
            {
                var request = await _dbContext.Requests.GetSimpleRequestById(model.RequestId);

                if ((await _authorizationService.AuthorizeAsync(User, request, Policies.CreateComplaint)).Succeeded)
                {
                    try
                    {
                        await _complaintService.Create(request, User.GetUserId(), User.TryGetImpersonatorId(), model.Message, model.ComplaintType.Value);

                        await _dbContext.SaveChangesAsync();
                    }
                    catch (InvalidOperationException ex)
                    {
                        _logger.LogError("Wrong status or complaint exists when trying to Create complaint. Status: {request.Status}, RequestId {request.RequestId}", request.Status, request.RequestId);
                        return(RedirectToAction("Index", "Home", new { errormessage = ex.Message }));
                    }
                    return(RedirectToAction("View", "Order", new { id = request.OrderId, tab = "complaint" }));
                }
                return(Forbid());
            }
            return(View(nameof(Create), model));
        }
Exemplo n.º 2
0
        public ActionResult Create([DataSourceRequest] DataSourceRequest request, ComplaintViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                _complaintService.Create(model);
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
Exemplo n.º 3
0
        public void Create(RequestStatus status)
        {
            var service = new ComplaintService(_tolkDbContext, _clock, _notificationService, _logger);
            var request = new Request
            {
                Status     = status,
                Complaints = new List <Complaint>()
            };

            _ = service.Create(request, 1, null, "apa", ComplaintType.BadDelivery);
        }
Exemplo n.º 4
0
        public void Create_InvalidStatus(RequestStatus status)
        {
            var service = new ComplaintService(_tolkDbContext, _clock, _notificationService, _logger);
            var request = new Request
            {
                Status     = status,
                Complaints = new List <Complaint>()
            };

            Assert.ThrowsAsync <InvalidOperationException>(() =>
                                                           service.Create(request, 1, null, "apa", ComplaintType.BadDelivery));
        }
Exemplo n.º 5
0
        public async Task <JsonResult> Create(ComplaintViewModel complaint)
        {
            try
            {
                using (ComplaintService complaintService = new ComplaintService())
                {
                    await complaintService.Create(complaint, User.Identity.GetUserId());
                }

                return(Json("Success", JsonRequestBehavior.AllowGet));
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        public IHttpActionResult Post([FromBody] ComplaintModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                _complaintService.Create(model);
                return(Ok(model));
            }
            catch (Exception ec)
            {
                return(BadRequest(ec.Message));
            }
        }