public void CheckLoadsForVisibility(List <LoadViewData> loads, string token, List <string> visibilityTypes) { string topsToGoErrors = null; string project44Errors = null; foreach (var load in loads) { var lte = _loadService.GetLatestTransaction(load.LoadId); if (lte.TransactionTypeId != "Accepted") { continue; } if (visibilityTypes.Contains(CarrierVisibilityTypes.TopsToGo)) { CheckLoadsForTopsToGoVisibilityData(load, lte, token, ref topsToGoErrors); } if (visibilityTypes.Contains(CarrierVisibilityTypes.Project44)) { CheckLoadsForProject44VisibilityData(load, lte, token, ref project44Errors); } } //Save all successful updates _context.SaveChanges("system"); //Throw any accumulated errors if (!string.IsNullOrWhiteSpace(topsToGoErrors) || !string.IsNullOrWhiteSpace(project44Errors)) { StringBuilder errors = new StringBuilder(); if (!string.IsNullOrWhiteSpace(topsToGoErrors)) { errors.Append(topsToGoErrors); } if (!string.IsNullOrWhiteSpace(project44Errors)) { if (errors.Length > 0) { errors.AppendLine(project44Errors); } else { errors.Append(project44Errors); } } throw new Exception(errors.ToString()); } }
public List <LocationData> AddOrUpdateLocations(Guid customerId, List <LocationData> locations, string username) { if (locations != null && locations.Count > 0) { foreach (var location in locations) { if (location != null) { location.CustomerId = customerId; if (location.LocationId > 0) { var dbLocation = _context.Locations.SingleOrDefault(x => x.CustomerId == customerId && x.LocationId == location.LocationId); if (dbLocation == null) { throw new Exception($"Location not found"); } _mapper.Map(location, dbLocation); } else { var dbLocation = _context.Locations.FirstOrDefault(x => x.CustomerId == customerId && x.LocationName.ToLower() == location.LocationName.ToLower()); if (dbLocation != null) { _mapper.Map(location, dbLocation); } else { dbLocation = _mapper.Map <LocationEntity>(location); _context.Locations.Add(dbLocation); } } } } _context.SaveChanges(username); } return(locations); }
public void UpdateUserData(Guid identUserId, string username, string firstName, string lastName) { var user = _context.Users.SingleOrDefault(x => x.IdentUserId == identUserId); if (user != null) { user.Username = username; user.FirstName = firstName; user.LastName = lastName; _context.SaveChanges(username); } }
public bool LogTransaction(Guid identUserId, string requestUri, string request, string response) { try { var customerId = GetCustomerId(identUserId); if (customerId.HasValue) { _context.CustomerTransactionLogs.Add(new CustomerTransactionLogEntity() { CustomerId = customerId.Value, RequestUri = requestUri, RequestJSON = request, ResponseJSON = response, IsSuccess = WasResponseSuccessful(response) }); _context.SaveChanges(_username); return(true); } } catch (Exception) { } return(false); }
public SaveLoadCarrierGroupResponse CreateLoadCarrierGroup(LoadCarrierGroupDetailData group, string username) { var response = new SaveLoadCarrierGroupResponse(); try { _securityService.GuardAction(SecurityActions.Loadshop_Ui_System_Shipper_Carrier_Groups_Add_Edit); ConvertStatesToAbbreviations(group); if (group.LoadCarrierGroupId > 0) { response.ModelState.AddModelError($"urn:LoadCarrierGroup", "LoadCarrierGroup should not have an LoadCarrierGroupId assigned when creating."); return(response); } var validationErrorMessage = ValidateLoadCarrierGroup(group); if (!string.IsNullOrWhiteSpace(validationErrorMessage)) { response.ModelState.AddModelError($"urn:LoadCarrierGroup", validationErrorMessage); return(response); } ValidateLoadCarrierGroupCarriers(group.Carriers, group.LoadCarrierGroupId); var dbGroup = _mapper.Map <LoadCarrierGroupEntity>(group); //Map Equipment Types dbGroup.LoadCarrierGroupEquipment = new List <LoadCarrierGroupEquipmentEntity>(); dbGroup.LoadCarrierGroupEquipment.MapList( group.LoadCarrierGroupEquipment, lcgeEntity => lcgeEntity.LoadCarrierGroupEquipmentId, lcgeData => lcgeData.LoadCarrierGroupEquipmentId, _mapper); dbGroup.LoadCarrierGroupCarriers = new List <LoadCarrierGroupCarrierEntity>(); dbGroup.LoadCarrierGroupCarriers.MapList( group.Carriers, lcgcEntity => lcgcEntity.LoadCarrierGroupCarrierId, legcData => legcData.LoadCarrierGroupCarrierId, _mapper); GuardCustomer(dbGroup.CustomerId); if (IsUnique(dbGroup)) { _context.LoadCarrierGroups.Add(dbGroup); //_context.LoadCarrierGroupEquipment.AddRange(dbGroup.LoadCarrierGroupEquipment); _context.SaveChanges(username); response.LoadCarrierGroupData = GetLoadCarrierGroup(dbGroup.LoadCarrierGroupId); } else { response.ModelState.AddModelError($"urn:LoadCarrierGroup", GetCarrierGroupUniqueConstraintErrorMessage(group)); } } catch (DbUpdateException ex) { //TODO: Improve to use sql database conditions if (ex.InnerException != null && ex.InnerException.Message.Contains("Violation of UNIQUE KEY constraint")) { response.ModelState.AddModelError($"urn:LoadCarrierGroup", GetCarrierGroupUniqueConstraintErrorMessage(group)); return(response); } throw; } return(response); }
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))); }