public async Task GetVehicleByName_WithExistentName_ShouldReturnCorrectResults()
        {
            string errorMessagePrefix = "VehicleService GetVehicleByName() method does not work properly.";

            var context = MdmsDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            _vehicleService = new VehicleService(context);

            VehicleServiceModel expectedData = context.Vehicles.SingleOrDefault(x => x.Name == "Mercedes_Actros_12345678901234567").To <VehicleServiceModel>();
            VehicleServiceModel actualData   = _vehicleService.GetVehicleByName("Mercedes_Actros_12345678901234567").Result;

            Assert.True(expectedData.Id == actualData.Id, errorMessagePrefix + " " + "Id is not returned properly.");
            Assert.True(expectedData.Name == actualData.Name, errorMessagePrefix + " " + "Name is not returned properly.");
            Assert.True(expectedData.Price == actualData.Price, errorMessagePrefix + " " + "Price is not returned properly.");
            Assert.True(expectedData.Picture == actualData.Picture, errorMessagePrefix + " " + "Picture is not returned properly.");
            Assert.True(expectedData.Depreciation == actualData.Depreciation, errorMessagePrefix + "Depreciation" + "Depreciation is not returned properly.");
            Assert.True(expectedData.Model == actualData.Model, errorMessagePrefix + " " + "Model is not returned properly.");
            Assert.True(expectedData.Make == actualData.Make, errorMessagePrefix + " " + "Make is not returned properly.");
            Assert.True(expectedData.VSN == actualData.VSN, errorMessagePrefix + " " + "VSN is not returned properly.");
            Assert.True(expectedData.Mileage == actualData.Mileage, errorMessagePrefix + " " + "Mileage is not returned properly.");
            Assert.True(expectedData.RegistrationNumber == actualData.RegistrationNumber, errorMessagePrefix + " " + "RegistrationNumber is not returned properly.");
            Assert.True(expectedData.IsInRepair == actualData.IsInRepair, errorMessagePrefix + " " + "IsInRepair is not returned properly.");
            Assert.True(expectedData.AcquiredOn == actualData.AcquiredOn, errorMessagePrefix + " " + "AcquiredOn is not returned properly.");
            Assert.True(expectedData.ManufacturedOn == actualData.ManufacturedOn, errorMessagePrefix + " " + "ManufacturedOn is not returned properly.");
            Assert.True(expectedData.IsActive == actualData.IsActive, errorMessagePrefix + " " + "IsActive is not returned properly.");
            Assert.True(expectedData.IsDeleted == actualData.IsDeleted, errorMessagePrefix + " " + "IsDeleted is not returned properly.");
            Assert.True(expectedData.VehicleProvider.Name == actualData.VehicleProvider.Name, errorMessagePrefix + " " + "VehicleProviderName is not returned properly.");
            Assert.True(expectedData.VehicleType.Name == actualData.VehicleType.Name, errorMessagePrefix + " " + "VehicleTypeName is not returned properly.");
        }
Example #2
0
        public async Task <VehicleDetailsModel> VehicleServiceSave(VehicleServiceModel model)
        {
            //calculating the total cost
            model.TotalServiceCost = model.MiscServiceCost;

            return(await vehicleRepository.VehicleServiceSave(model));
        }
Example #3
0
        public async Task <VehicleDetailsModel> VehicleServiceSave(VehicleServiceModel model)
        {
            VehicleServiceEntity entity;

            decimal serviceCost = model.TotalServiceCost;

            if (model.VehicleServiceId != 0)
            {
                VehicleServiceEntity currentServiceEntity = await this.SingleAsync <VehicleServiceEntity>(e => e.VehicleServiceId == model.VehicleServiceId);

                serviceCost = model.TotalServiceCost - currentServiceEntity.TotalServiceCost;

                entity = await this.UpdateEntity <VehicleServiceEntity, VehicleServiceModel>(currentServiceEntity, model, false);
            }
            else
            {
                entity = await this.AddEntity <VehicleServiceEntity, VehicleServiceModel>(model, false);
            }

            // updating the vehicle details
            await this.VehicleServiceVehicleUpdate(entity, serviceCost);

            await this.DbContext.SaveChangesAsync();

            return(await this.VehicleDetailsGet(model.VehicleId));
        }
Example #4
0
        public async void VehicleServiceUpdate()
        {
            // Arrange
            this.VehicleReferrentialTables();
            this.VehicleTable();
            this.VehicleServiceTable();

            await this.SaveChangesAsync(this.FleetDbContext);

            VehicleServiceModel model = new VehicleServiceModel()
            {
                VehicleServiceId = 1, VehicleId = 1, MiscServiceCost = 200, ServiceDate = new DateTime(2016, 10, 1)
            };

            // Act
            AjaxModel <VehicleDetailsModel> ajaxModel = await this.Controller.VehicleServiceUpdate(model);

            VehicleDetailsModel vehicle = ajaxModel.Model;

            // Assert
            Assert.Equal(ajaxModel.Message, FleetMessages.VehicleServiceSaveSuccess);
            Assert.Equal(vehicle.ServiceDate, new DateTime(2016, 10, 1));
            Assert.Equal(vehicle.ServiceCost, 400M);
            Assert.Equal(vehicle.ServiceRecord.Count, 2);
        }
        public async Task <VehicleServiceModel> CreateVehicleService(VehicleServiceModel service)
        {
            var res = _context.Set <VehicleServiceModel>().Add(service);
            await _context.SaveChangesAsync();

            return(res);
        }
Example #6
0
        public ActionResult UpdateVehicleService(VehicleServiceModel updateService)
        {
            if (updateService.ServiceDate.Year < minimumYear)
            {
                ViewBag.Message = "You did not enter a valid date";
                return(View("Error"));
            }
            var vehicleServiceUpdateRequest = new VehicleServiceDto
            {
                VehicleServiceId   = updateService.VehicleServiceId,
                VehicleId          = updateService.VehicleId,
                ServiceDate        = updateService.ServiceDate,
                ServiceType        = updateService.ServiceType,
                IsServiceCompleted = updateService.IsServiceCompleted
            };
            string jsonCreateCustomer = JsonConvert.SerializeObject(vehicleServiceUpdateRequest);
            var    httpContent        = new StringContent(jsonCreateCustomer, Encoding.UTF8, "application/json");

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Session["tokenkey"].ToString());

                var response = client.PostAsync(new Uri(_endpoints.UpdateVehicleService), httpContent).Result;

                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(View("Error"));
                }
            }
            ViewBag.Message = "Vehicleservice has been updated";
            return(View("Success"));
        }
Example #7
0
        public async Task Add(VehicleServiceModel vehicle)
        {
            var dbVehicle = Mapper.Map <Vehicle>(vehicle);

            await this.db.Vehicles.AddAsync(dbVehicle);

            await this.db.SaveChangesAsync();
        }
Example #8
0
        //==================================================================//
        //==================================================================//
        //==================  VEHICLESERVICE CONTROLLERS  ==================//
        //==================================================================//
        //==================================================================//


        //============BOOK=VEHICLESERVICE===============================
        public ActionResult BookVehicleService(VehicleModel getvehicleid)
        {
            VehicleServiceModel vehicleService = new VehicleServiceModel {
                VehicleId = getvehicleid.VehicleId
            };

            return(View("BookVehicleService", vehicleService));
        }
Example #9
0
 public VehicleServiceViewModel(
     IEventAggregator eventAggregator,
     VehicleServiceModel vehicleServiceModel,
     VehicleService vehicleService
     )
 {
     _eventAggregator    = eventAggregator;
     _vehicleServiceData = vehicleServiceModel;
     _vehicleService     = vehicleService;
 }
Example #10
0
        // Vehicle Service
        public async Task <VehicleServiceModel> VehicleServiceGet(int vehicleServiceId)
        {
            VehicleServiceModel model = await this.SingleOrDefaultAsync <VehicleServiceEntity, VehicleServiceModel>(e => e.VehicleServiceId == vehicleServiceId);

            // for adding return blank model
            if (model == null)
            {
                model = new VehicleServiceModel()
                {
                    ServiceDate = DateTime.Now
                };
            }

            return(model);
        }
Example #11
0
        public async Task <bool> Edit(VehicleServiceModel vehicleServiceModel)
        {
            Vehicle vehicle = AutoMapper.Mapper.Map <Vehicle>(vehicleServiceModel);

            if (vehicle.IsDeleted)
            {
                return(false);
            }

            vehicle.VehicleProvider = await GetVehicleProviderByName(vehicleServiceModel.VehicleProvider.Name);

            vehicle.VehicleType = await GetVehicleTypeByName(vehicleServiceModel.VehicleType.Name);

            _context.Vehicles.Update(vehicle);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Example #12
0
        public async Task <bool> Create(VehicleServiceModel vehicleServiceModel)
        {
            if (_context.Vehicles.Any(v => v.VSN == vehicleServiceModel.VSN))
            {
                return(false);
            }

            Vehicle vehicle = AutoMapper.Mapper.Map <Vehicle>(vehicleServiceModel);

            vehicle.VehicleProvider = await GetVehicleProviderByName(vehicleServiceModel.VehicleProvider.Name);

            vehicle.VehicleType = await GetVehicleTypeByName(vehicleServiceModel.VehicleType.Name);

            _context.Vehicles.Add(vehicle);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Example #13
0
        public async Task <VehicleDetailsModel> VehicleServiceSave(VehicleServiceModel model)
        {
            decimal serviceCost = model.TotalServiceCost;

            if (model.VehicleServiceId != 0)
            {
                VehicleServiceEntity currentService = await(from vsm in this.DbContext.VehicleServices where vsm.VehicleServiceId == model.VehicleServiceId select vsm).SingleAsync();
                serviceCost = model.TotalServiceCost - currentService.TotalServiceCost;
            }

            //saving vehicle service and updating the vehicle details
            VehicleServiceEntity entity = await SaveEntity <VehicleServiceEntity, VehicleServiceModel>(model, false);

            await VehicleServiceVehicleUpdate(entity, serviceCost);

            await this.DbContext.SaveChangesAsync();

            return(await  VehicleDetailsGet(model.VehicleId));
        }
        public async Task CreateVehicle_NotExistentPartProvider_ShouldNotCreatePart()
        {
            string errorMessagePrefix = "VehicleService Create() method does not work properly.";

            var context = MdmsDbContextInMemoryFactory.InitializeContext();

            await SeedData(context);

            _vehicleService = new VehicleService(context);

            var vehicle = new VehicleServiceModel()
            {
                Id                 = "V3",
                Name               = "BMW_M5_12345678901234512",
                Price              = 2000000.2M,
                Depreciation       = 20000.1m,
                Picture            = "/Here/here/jpeg2.png",
                Make               = "BMW",
                Model              = "S500",
                VSN                = "12345678901234568",
                Mileage            = 150000,
                RegistrationNumber = "CA5152AB",
                IsInRepair         = false,
                AcquiredOn         = DateTime.ParseExact("11/21/2018 11:23", "M/d/yyyy hh:mm", CultureInfo.InvariantCulture),
                ManufacturedOn     = DateTime.ParseExact("1/21/2019 11:23", "M/d/yyyy hh:mm", CultureInfo.InvariantCulture),
                IsActive           = true,
                VehicleProvider    = new VehicleProviderServiceModel()
                {
                    Name = "Mercedes"
                },

                VehicleType = new VehicleTypeServiceModel()
                {
                    Name = "Car"
                },
                IsDeleted = false
            };

            bool actualResult = await _vehicleService.Create(vehicle);

            Assert.False(actualResult, errorMessagePrefix);
        }
Example #15
0
        public async Task <VehicleServiceModel> VehicleServiceGet(int vehicleServiceId)
        {
            var serviceQuery = from service in this.DbContext.VehicleServices
                               where service.VehicleServiceId == vehicleServiceId
                               select Mapper.Map <VehicleServiceEntity, VehicleServiceModel>(service);

            VehicleServiceModel model = await serviceQuery.SingleOrDefaultAsync();

            //for adding return blank model
            if (model == null)
            {
                model = new VehicleServiceModel()
                {
                    ServiceDate = DateTime.Now
                }
            }
            ;

            return(model);
        }
Example #16
0
        public async void VehicleServiceAdd()
        {
            // Arrange
            this.VehicleReferrentialTables();
            this.VehicleTable();
            this.VehicleServiceTable();

            await this.SaveChangesAsync(this.FleetDbContext);

            VehicleServiceModel model = new VehicleServiceModel() { VehicleServiceId = 0, VehicleId = 1, MiscServiceCost = 200, ServiceDate = new DateTime(2016, 10, 1) };

            // Act
            AjaxModel<VehicleDetailsModel> ajaxModel = await this.Controller.VehicleServiceAdd(model);
            VehicleDetailsModel vehicle = ajaxModel.Model;

            // Assert
            Assert.Equal(ajaxModel.Message, FleetMessages.VehicleServiceSaveSuccess);
            Assert.Equal(vehicle.ServiceDate, new DateTime(2016, 10, 1));
            Assert.Equal(vehicle.ServiceCost, 500.50M);
            Assert.Equal(vehicle.ServiceRecord.Count, 3);
        }
Example #17
0
        public async void VehicleServiceGet(int vehicleServiceId)
        {
            // Arrange
            this.VehicleServiceTable();
            await this.SaveChangesAsync(this.FleetDbContext);

            // Act
            AjaxModel <VehicleServiceModel> ajaxModel = await this.Controller.VehicleServiceGet(vehicleServiceId);

            VehicleServiceModel model = ajaxModel.Model;

            // Assert
            if (vehicleServiceId == 1)
            {
                Assert.Equal(model.ServiceDate, new DateTime(2016, 1, 1));
                Assert.Equal(model.TotalServiceCost, 100.50M);
            }
            else
            {
                Assert.Equal(model.ServiceDate.Value.Date, DateTime.Now.Date);
                Assert.Equal(model.TotalServiceCost, 0);
            }
        }
Example #18
0
        public async Task <IActionResult> Create(VehicleCreateBindingModel vehicleCreateBindingModel)
        {
            if (ModelState.IsValid)
            {
                string pictureUrl = await _cloudinaryService.UploadPictureAsync(vehicleCreateBindingModel.Picture,
                                                                                vehicleCreateBindingModel.VSN);

                VehicleServiceModel vehicleServiceModel =
                    AutoMapper.Mapper.Map <VehicleServiceModel>(vehicleCreateBindingModel);
                vehicleServiceModel.Picture = pictureUrl;

                var result = await _vehicleService.Create(vehicleServiceModel);

                if (result)
                {
                    return(this.RedirectToAction("All"));
                }

                this.ViewData["error"] = ControllerConstants.VehicleCreateErrorMessage;
                return(this.View(vehicleCreateBindingModel));
            }
            this.ViewData["error"] = ControllerConstants.InputErrorMessage;
            return(this.View(vehicleCreateBindingModel));
        }
Example #19
0
 public async Task <AjaxModel <VehicleDetailsModel> > VehicleServiceUpdate([FromBody] VehicleServiceModel model)
 {
     return(await AjaxHelper.SaveGetAsync(m => domain.VehicleServiceSave(model), Messages.Fleet.VehicleServiceSaveSuccess));
 }