Пример #1
0
        public async Task <int> SaveCustomerVehicle(CustomerVehicle customerVehicleDao)
        {
            using (var dbContext = new CustomerVehicleContext(_connectionString))
            {
                var existingCustomerVehicle = GetCustomerVehicle(customerVehicleDao.CustomerId, customerVehicleDao.VehicleNo);

                if (existingCustomerVehicle == null)
                {
                    existingCustomerVehicle = dbContext.CustomerVehicles.Add(customerVehicleDao);
                }
                else
                {
                    existingCustomerVehicle.RegistrationNo     = customerVehicleDao.RegistrationNo;
                    existingCustomerVehicle.VinNumber          = customerVehicleDao.VinNumber;
                    existingCustomerVehicle.MakeCode           = customerVehicleDao.MakeCode;
                    existingCustomerVehicle.ModelCode          = customerVehicleDao.ModelCode;
                    existingCustomerVehicle.ModelYear          = customerVehicleDao.ModelYear;
                    existingCustomerVehicle.ModelDescription   = customerVehicleDao.ModelDescription;
                    existingCustomerVehicle.LastServiceDate    = customerVehicleDao.LastServiceDate;
                    existingCustomerVehicle.NextServiceDate    = customerVehicleDao.NextServiceDate;
                    existingCustomerVehicle.LastKnownMileage   = customerVehicleDao.LastKnownMileage;
                    existingCustomerVehicle.NextServiceMileage = customerVehicleDao.NextServiceMileage;
                    existingCustomerVehicle.VariantCode        = customerVehicleDao.VariantCode;
                    dbContext.CustomerVehicles.AddOrUpdate(existingCustomerVehicle);
                }

                await dbContext.SaveChangesAsync();

                return(existingCustomerVehicle.Id);
            }
        }
Пример #2
0
 public CustomerVehicle GetCustomerVehicle(int customerId, int vehicleNo)
 {
     using (var dbContext = new CustomerVehicleContext(_connectionString))
     {
         return(dbContext.CustomerVehicles.FirstOrDefault(cv =>
                                                          cv.CustomerId == customerId && cv.VehicleNo == vehicleNo));
     }
 }
Пример #3
0
 public Customer GetCustomer(int customerNo, string roofTopId, string communityId)
 {
     using (var dbContext = new CustomerVehicleContext(_connectionString))
     {
         return(dbContext.Customers.FirstOrDefault(cv =>
                                                   cv.CustomerNo == customerNo && cv.RooftopId == roofTopId && cv.CommunityId == communityId));
     }
 }
Пример #4
0
 public async Task SaveServiceBooking(ServiceBookings serviceBooking)
 {
     using (var dbContext = new CustomerVehicleContext(_connectionString))
     {
         dbContext.ServiceBookings.Add(serviceBooking);
         await dbContext.SaveChangesAsync();
     }
 }
Пример #5
0
 public async Task LogInvitationDetail(Invitation invitationDao)
 {
     using (var dbContext = new CustomerVehicleContext(_connectionString))
     {
         dbContext.Invitations.Add(invitationDao);
         await dbContext.SaveChangesAsync();
     }
 }
Пример #6
0
 public ServiceBookings GetServiceBooking(int customerId, int vehicleNo, int dealerId)
 {
     using (var dbContext = new CustomerVehicleContext(_connectionString))
     {
         return(dbContext.ServiceBookings.Where(x => x.CustomerNo == customerId &&
                                                x.VehicleNo == vehicleNo &&
                                                x.DealerId == dealerId)
                .OrderByDescending(x => x.CreateTime).FirstOrDefault());
     }
 }
Пример #7
0
        public async Task DeleteCustomerVehicle(int customerId, int vehicleNo)
        {
            using (var dbContext = new CustomerVehicleContext(_connectionString))
            {
                var customerVehicles = dbContext.CustomerVehicles.Where(cv =>
                                                                        cv.CustomerId == customerId && cv.VehicleNo == vehicleNo);

                if (customerVehicles.Any())
                {
                    dbContext.CustomerVehicles.RemoveRange(customerVehicles);
                    await dbContext.SaveChangesAsync();
                }
            }
        }
Пример #8
0
        public async Task <int> SaveCustomer(Customer customerDao)
        {
            using (var dbContext = new CustomerVehicleContext(_connectionString))
            {
                var existingCustomer = GetCustomer(customerDao.CustomerNo, customerDao.RooftopId, customerDao.CommunityId);
                if (existingCustomer == null)
                {
                    existingCustomer = dbContext.Customers.Add(customerDao);
                }
                else
                {
                    customerDao.Id = existingCustomer.Id;
                    existingCustomer.CustomerEmail = customerDao.CustomerEmail;
                    existingCustomer.FirstName     = customerDao.FirstName;
                    existingCustomer.Surname       = customerDao.Surname;
                    existingCustomer.PhoneNumber   = customerDao.PhoneNumber;
                    dbContext.Customers.AddOrUpdate(existingCustomer);
                }

                await dbContext.SaveChangesAsync();

                return(existingCustomer.Id);
            }
        }