Esempio n. 1
0
        public async Task <string> AddVehicleAsync(VehicleInputModel input)
        {
            if (this.vehicles.AllAsNoTracking().Any(v => v.RegNumber == input.RegNumber))
            {
                throw new ArgumentException("Vehicle already exist.");
            }

            var vehicle = new Vehicle
            {
                TypeId        = input.TypeId,
                LoadingBodyId = input.LoadingBodyId == 0 ? null : input.LoadingBodyId,
                CompanyId     = input.CompanyId,
                DriverId      = input.DriverId == "null" ? null : input.DriverId,
                TrailerId     = input.TrailerId == "null" ? null : input.TrailerId,
                RegNumber     = input.RegNumber,
                Name          = input.Name,
                Details       = input.Details,
            };

            await this.vehicles.AddAsync(vehicle);

            await this.vehicles.SaveChangesAsync();

            return(vehicle.Id);
        }
Esempio n. 2
0
        private Vehicle MapVehicle(VehicleInputModel vehicleInput)
        {
            Vehicle vehicle = new Vehicle();

            vehicle.Placa       = vehicleInput.Placa;
            vehicle.Make        = vehicleInput.Make;
            vehicle.Model       = vehicleInput.Model;
            vehicle.Domiciliary = MapDomiciliary(vehicleInput.Domiciliary);

            return(vehicle);
        }
Esempio n. 3
0
        public async Task <IActionResult> AddTruckModal(VehicleInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input = this.vehiclesService.LoadVehicleInputModel(input);
                return(this.View(input));
            }

            await this.vehiclesService.AddVehicleAsync(input);

            return(this.Json(new { isValid = true, redirectToUrl = string.Empty }));
        }
Esempio n. 4
0
        public async Task <IActionResult> AddVehicle(VehicleInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input = this.vehiclesService.LoadVehicleInputModel(input);
                return(this.View(input));
            }

            await this.vehiclesService.AddVehicleAsync(input);

            return(this.RedirectToAction(GlobalConstants.Index));
        }
        public async Task <IHttpActionResult> Post(int id, VehicleInputModel model)
        {
            Vehicle vehicle = new Vehicle()
            {
                Id = model.Id, VehicleToBrakeConfigCount = model.VehicleToBrakeConfigCount
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment
            };
            var attachments     = SetUpAttachmentsModels(model.Attachments);
            var changeRequestId = await _vehicleApplicationService.DeleteAsync(vehicle, id, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
Esempio n. 6
0
        public ActionResult <VehicleViewModel> Post(VehicleInputModel vehicleInput)
        {
            Vehicle vehicle = MapVehicle(vehicleInput);

            var response = vehicleService.Save(vehicle);

            if (response.Error)
            {
                ModelState.AddModelError("Guardar Domiciliario", response.Message);
                var problemDetails = new ValidationProblemDetails(ModelState)
                {
                    Status = StatusCodes.Status400BadRequest,
                };
                return(BadRequest(problemDetails));
            }

            return(Ok(response.Vehicle));
        }
Esempio n. 7
0
        public VehicleInputModel LoadVehicleInputModel(VehicleInputModel model = null)
        {
            if (model is null)
            {
                model = new VehicleInputModel();
            }

            model.CompanyItems = this.companies.AllAsNoTracking()
                                 .Select(c => new System.Collections.Generic.KeyValuePair <string, string>(c.Id.ToString(), c.Name))
                                 .ToList();
            model.TypeItems = this.types.AllAsNoTracking()
                              .Select(t => new System.Collections.Generic.KeyValuePair <string, string>(t.Id.ToString(), t.Name))
                              .ToList();
            model.LoadingBodyItems = this.loadingBodies.AllAsNoTracking()
                                     .Select(lb => new System.Collections.Generic.KeyValuePair <string, string>(lb.Id.ToString(), lb.Name))
                                     .ToList();
            return(model);
        }
        public async Task <IHttpActionResult> Post(VehicleInputModel model)
        {
            Vehicle vehicle = new Vehicle()
            {
                BaseVehicleId = model.BaseVehicleId,
                SubModelId    = model.SubModelId,
                SourceId      = model.SourceId,
                RegionId      = model.RegionId
            };
            var attachments = SetUpAttachmentsModels(model.Attachments);

            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = model.Comment
            };

            var changeRequestId = await _vehicleApplicationService.AddAsync(vehicle, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }
Esempio n. 9
0
        public async Task <IActionResult> AddVehicleModal(VehicleInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                input = this.vehiclesService.LoadVehicleInputModel(input);
                return(this.Json(new { isValid = false, redirectToUrl = string.Empty, html = this.View(input) }));
            }

            try
            {
                await this.vehiclesService.AddVehicleAsync(input);
            }
            catch (Exception ex)
            {
                this.notyfService.Error(this.localizer[ex.Message]);
                input = this.vehiclesService.LoadVehicleInputModel(input);
                return(this.Json(new { isValid = false, redirectToUrl = string.Empty, html = this.View(input) }));
            }

            return(this.Json(new { isValid = true, redirectToUrl = string.Empty }));
        }
Esempio n. 10
0
        public async Task <IHttpActionResult> Put(int id, VehicleInputModel updatedVehicle)
        {
            Vehicle vehicle = new Vehicle()
            {
                Id                            = updatedVehicle.Id,
                BaseVehicleId                 = updatedVehicle.BaseVehicleId,
                SubModelId                    = updatedVehicle.SubModelId,
                SourceId                      = updatedVehicle.SourceId,
                RegionId                      = updatedVehicle.RegionId,
                VehicleToBrakeConfigCount     = updatedVehicle.VehicleToBrakeConfigCount,
                VehicleToBedConfigCount       = updatedVehicle.VehicleToBedConfigCount,
                VehicleToBodyStyleConfigCount = updatedVehicle.VehicleToBodyStyleConfigCount
            };
            CommentsStagingModel comment = new CommentsStagingModel()
            {
                Comment = updatedVehicle.Comment
            };
            var attachments     = SetUpAttachmentsModels(updatedVehicle.Attachments);
            var changeRequestId = await _vehicleApplicationService.UpdateAsync(vehicle, id, CurrentUser.Email, comment, attachments);

            return(Ok(changeRequestId));
        }