public CustomerCarrierScacContractData AddCarrierToShipper(Guid customerId, string scac, Guid userId) { _securityService.GuardAction(SecurityActions.Loadshop_Ui_System_Shipper_Contracted_Carriers_Add_Edit); var customerCarrierScacContractEntity = new CustomerCarrierScacContractEntity { CustomerId = customerId, Scac = scac }; var user = _context.Users.Where(x => x.IdentUserId == userId).FirstOrDefault(); _context.CustomerCarrierScacContracts.Add(customerCarrierScacContractEntity); _context.SaveChanges(user.Username); return(_mapper.Map <CustomerCarrierScacContractData>(customerCarrierScacContractEntity)); }
public List <CustomerCarrierScacContractData> AddCarriersToShipper(Guid customerId, List <string> scacs, Guid userId) { _securityService.GuardAction(SecurityActions.Loadshop_Ui_System_Shipper_Contracted_Carriers_Add_Edit); var user = _context.Users.Where(x => x.IdentUserId == userId).FirstOrDefault(); var customerCarrierScacContractEntities = new List <CustomerCarrierScacContractEntity>(); foreach (var scac in scacs) { var customerCarrierScacContractEntity = new CustomerCarrierScacContractEntity { CustomerId = customerId, Scac = scac }; customerCarrierScacContractEntities.Add(customerCarrierScacContractEntity); } _context.CustomerCarrierScacContracts.AddRange(customerCarrierScacContractEntities); _context.SaveChanges(user.Username); return(_mapper.Map <List <CustomerCarrierScacContractData> >(customerCarrierScacContractEntities)); }
public CustomerProfileData AddShipper(CustomerProfileData customer, string username) { _securityService.GuardAction(SecurityActions.Loadshop_Ui_System_Shipper_Add_Edit); if (customer != null && !customer.CustomerLoadTypeId.HasValue) { customer.CustomerLoadTypeExpirationDate = null; } ValidateCustomerOrderType(customer); ValidateFeeStructure(customer); SendFeeChangeEmail(null, customer, "Test"); var dbCustomer = _mapper.Map <CustomerEntity>(customer); dbCustomer.DataSource = "LOADSHOP"; _context.Customers.Add(dbCustomer); if (customer.CustomerCarrierScacs.Any()) { dbCustomer.CustomerCarrierScacContracts = new List <CustomerCarrierScacContractEntity>(); } foreach (var scac in customer.CustomerCarrierScacs) { var dbCustomerCarrierScac = new CustomerCarrierScacContractEntity { Scac = scac }; dbCustomer.CustomerCarrierScacContracts.Add(dbCustomerCarrierScac); } _context.SaveChanges(username); return(_mapper.Map <CustomerProfileData>(GetDbShipper(dbCustomer.CustomerId))); }
public CustomerProfileData UpdateShipper(CustomerProfileData customer, string username) { _securityService.GuardAction(SecurityActions.Loadshop_Ui_System_Shipper_Add_Edit); if (customer != null && !customer.CustomerLoadTypeId.HasValue) { customer.CustomerLoadTypeExpirationDate = null; } if (!customer.CustomerId.HasValue) { throw new Exception("Customer Id cannot be null"); } ValidateCustomerOrderType(customer); ValidateFeeStructure(customer); var dbCustomer = GetDbShipper(customer.CustomerId.Value); SendFeeChangeEmail(dbCustomer, customer, "Test"); dbCustomer.Name = customer.Name; dbCustomer.DefaultCommodity = customer.DefaultCommodity; dbCustomer.UseFuelRerating = customer.UseFuelRerating; dbCustomer.FuelReratingNumberOfDays = Math.Abs(customer.FuelReratingNumberOfDays.GetValueOrDefault(0)); dbCustomer.AllowZeroFuel = customer.AllowZeroFuel; dbCustomer.AllowEditingFuel = customer.AllowEditingFuel; dbCustomer.TopsOwnerId = customer.TopsOwnerId; dbCustomer.SuccessManagerUserId = customer.SuccessManagerUserId; dbCustomer.SuccessSpecialistUserId = customer.SuccessSpecialistUserId; dbCustomer.Comments = customer.Comments; dbCustomer.CustomerLoadTypeId = customer.CustomerLoadTypeId; dbCustomer.CustomerLoadTypeExpirationDate = customer.CustomerLoadTypeExpirationDate; dbCustomer.AutoPostLoad = customer.AutoPostLoad; dbCustomer.ValidateUniqueReferenceLoadIds = customer.ValidateUniqueReferenceLoadIds; dbCustomer.AllowManualLoadCreation = customer.AllowManualLoadCreation; dbCustomer.InNetworkFlatFee = customer.InNetworkFlatFee; dbCustomer.InNetworkPercentFee = customer.InNetworkPercentFee; dbCustomer.OutNetworkFlatFee = customer.OutNetworkFlatFee; dbCustomer.OutNetworkPercentFee = customer.OutNetworkPercentFee; dbCustomer.InNetworkFeeAdd = customer.InNetworkFeeAdd; dbCustomer.OutNetworkFeeAdd = customer.OutNetworkFeeAdd; dbCustomer.RequireMarginalAnalysis = customer.RequireMarginalAnalysis; // Customer Contacts foreach (var customerContact in customer.CustomerContacts) { var dbCustomerContact = _context.CustomerContacts .SingleOrDefault(x => x.CustomerContactId == customerContact.CustomerContactId); if (dbCustomerContact == null) { dbCustomerContact = _mapper.Map <CustomerContactEntity>(customerContact); dbCustomer.CustomerContacts.Add(dbCustomerContact); } else { dbCustomerContact.FirstName = customerContact.FirstName; dbCustomerContact.LastName = customerContact.LastName; dbCustomerContact.Position = customerContact.Position; dbCustomerContact.PhoneNumber = customerContact.PhoneNumber; dbCustomerContact.Email = customerContact.Email; } } foreach (var dbCustomerContact in dbCustomer.CustomerContacts.Where(x => x.CustomerContactId != Guid.Empty)) { if (customer.CustomerContacts.All(x => x.CustomerContactId != dbCustomerContact.CustomerContactId)) { _context.CustomerContacts.Remove(dbCustomerContact); } } //Only update if user has access if (_securityService.UserHasAction(SecurityActions.Loadshop_Ui_System_Shipper_Contracted_Carriers_Add_Edit)) { // Customer Carrier Scacs var dbCustomerCarrierScacs = _context.CustomerCarrierScacContracts.Where(x => x.CustomerId == customer.CustomerId).ToList(); foreach (var scac in customer.CustomerCarrierScacs) { var dbCustomerCarrierScac = dbCustomerCarrierScacs.SingleOrDefault(x => x.Scac == scac); if (dbCustomerCarrierScac == null) { dbCustomerCarrierScac = new CustomerCarrierScacContractEntity { Scac = scac }; dbCustomerCarrierScacs.Add(dbCustomerCarrierScac); dbCustomer.CustomerCarrierScacContracts.Add(dbCustomerCarrierScac); } } foreach (var dbScac in dbCustomer.CustomerCarrierScacContracts.Where(x => x.CustomerCarrierContractId != Guid.Empty)) { if (customer.CustomerCarrierScacs.All(x => x != dbScac.Scac)) { _context.CustomerCarrierScacContracts.Remove(dbScac); } } } _context.SaveChanges(username); return(_mapper.Map <CustomerProfileData>(GetDbShipper(dbCustomer.CustomerId))); }