public async Task <IActionResult> UpdateTransporter(Guid id, [FromBody] TransporterRequestModel transporterRequestModel)
        {
            //var loggedIn = User.Claims.FirstOrDefault(c => c.Type == "sub").Value;


            var Transporter = await QueryRouter.QueryAsync <GetTransporterById, Transporter>(new GetTransporterById(id));

            if (Transporter != null)
            {
                if (String.IsNullOrEmpty(transporterRequestModel.Name))
                {
                    transporterRequestModel.Name = Transporter.Name;
                }
                if (String.IsNullOrEmpty(transporterRequestModel.Address))
                {
                    transporterRequestModel.Address = Transporter.Address;
                }
                if (transporterRequestModel.Telephone == 0)
                {
                    transporterRequestModel.Telephone = Transporter.Telephone;
                }
                if (String.IsNullOrEmpty(transporterRequestModel.Email))
                {
                    transporterRequestModel.Email = Transporter.Email;
                }
            }

            var result = await CommandRouter.RouteAsync <UpdateTransporterCommand, IdResponse>(
                new UpdateTransporterCommand(transporterRequestModel.Email, transporterRequestModel.Telephone,
                                             transporterRequestModel.Address, transporterRequestModel.Name, id)
                );

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
        public async Task <IActionResult> CreateNewTransporter([FromBody] TransporterRequestModel transporterRequestModel)
        {
            var result = await CommandRouter.RouteAsync <CreateTransporterCommand, IdResponse>(
                new CreateTransporterCommand(transporterRequestModel.Email,
                                             transporterRequestModel.Telephone, transporterRequestModel.Address,
                                             transporterRequestModel.Name));

            return(!result.IsSuccessful ? Conflict(result) : new ObjectResult(result));
        }
Beispiel #3
0
        public async Task <OperationDataResult <TransportersModel> > Index(TransporterRequestModel pnRequestModel)
        {
            try
            {
                var transportersModel = new TransportersModel();

                var transporterQuery = _dbContext.Transporters.AsQueryable();

                if (!pnRequestModel.NameFilter.IsNullOrEmpty() && pnRequestModel.NameFilter != "")
                {
                    transporterQuery = transporterQuery.Where(x =>
                                                              x.Name.Contains(pnRequestModel.NameFilter) ||
                                                              x.Description.Contains(pnRequestModel.NameFilter));
                }
                if (!string.IsNullOrEmpty(pnRequestModel.Sort))
                {
                    if (pnRequestModel.IsSortDsc)
                    {
                        transporterQuery = transporterQuery
                                           .CustomOrderByDescending(pnRequestModel.Sort);
                    }
                    else
                    {
                        transporterQuery = transporterQuery
                                           .CustomOrderBy(pnRequestModel.Sort);
                    }
                }
                else
                {
                    transporterQuery = _dbContext.Transporters
                                       .OrderBy(x => x.Id);
                }

                transporterQuery
                    = transporterQuery
                      .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
                      .Skip(pnRequestModel.Offset)
                      .Take(pnRequestModel.PageSize);
                var transporters = await transporterQuery.Select(x => new TransporterModel
                {
                    Id            = x.Id,
                    Name          = x.Name,
                    Description   = x.Description,
                    ForeignId     = x.ForeignId,
                    Address       = x.Address,
                    City          = x.City,
                    ZipCode       = x.ZipCode,
                    Phone         = x.Phone,
                    ContactPerson = x.ContactPerson
                }).ToListAsync();

                transportersModel.Total =
                    _dbContext.Transporters.Count(x => x.WorkflowState != Constants.WorkflowStates.Removed);
                transportersModel.TransporterList = transporters;

                return(new OperationDataResult <TransportersModel>(true, transportersModel));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _coreHelper.LogException(e.Message);
                return(new OperationDataResult <TransportersModel>(false,
                                                                   _trashInspectionLocalizationService.GetString("ErrorObtainingTransporters")));
            }
        }
 public async Task <OperationDataResult <TransportersModel> > Index(TransporterRequestModel requestModel)
 {
     return(await _transporterService.Index(requestModel));
 }