public ConfigurationController(IMemoryCache cache, IHostingEnvironment hostingEnvironment, LogisticsContext dbContext) { _cache = cache; _dbContext = dbContext; _hostingEnvironment = hostingEnvironment; _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); }
private int CreateNewAccount(Lms_CustomerPoco customerPoco) { int newAccountId = 0; _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext)); var parentGLForCustomerAccount = _configurationLogic.GetSingleById(1).ParentGLForCustomerAccount; var accounts = _chartOfAccountLogic.GetList().Where(c => c.ParentGLCode == parentGLForCustomerAccount).ToList(); newAccountId = accounts.Max(c => c.Id) + 1; Lms_ChartOfAccountPoco accountPoco = new Lms_ChartOfAccountPoco(); accountPoco.Id = newAccountId; accountPoco.ParentGLCode = parentGLForCustomerAccount; accountPoco.AccountName = customerPoco.CustomerName; accountPoco.BranchId = sessionData.BranchId == null ? 1 : (int)sessionData.BranchId; accountPoco.CurrentBalance = 0; accountPoco.IsActive = true; accountPoco.Remarks = "Customer Account Receivable"; accountPoco.CreateDate = DateTime.Now; accountPoco.CreatedBy = sessionData.UserId; var newAcc = _chartOfAccountLogic.Add(accountPoco); if (newAcc != null) { return(newAccountId); } else { return(0); } }
public IActionResult Add([FromBody] dynamic employeeData) { ValidateSession(); var result = ""; try { if (employeeData != null) { Lms_EmployeePoco employeePoco = JsonConvert.DeserializeObject <Lms_EmployeePoco>(JsonConvert.SerializeObject(employeeData[0])); if (employeePoco.Id < 1 && employeePoco.FirstName.Trim() != string.Empty) { _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext)); var parentGLForEmployeeAccount = _configurationLogic.GetSingleById(1).ParentGLForEmployeeAccount; var accounts = _chartOfAccountLogic.GetList().Where(c => c.ParentGLCode == parentGLForEmployeeAccount).ToList(); var newAccountId = accounts.Max(c => c.Id) + 1; var newEmployeeId = _employeeLogic.GetMaxId() + 1; using (var scope = new TransactionScope()) { Lms_ChartOfAccountPoco accountPoco = new Lms_ChartOfAccountPoco(); accountPoco.Id = newAccountId; accountPoco.ParentGLCode = parentGLForEmployeeAccount; accountPoco.AccountName = employeePoco.FirstName + employeePoco.LastName; accountPoco.BranchId = sessionData.BranchId == null ? 1 : (int)sessionData.BranchId; accountPoco.CurrentBalance = 0; accountPoco.IsActive = true; accountPoco.Remarks = "Employee Account Payable"; accountPoco.CreateDate = DateTime.Now; accountPoco.CreatedBy = sessionData.UserId; var addedAcc = _chartOfAccountLogic.Add(accountPoco); if (addedAcc.Id > 0) { employeePoco.Id = newEmployeeId; employeePoco.AccountId = addedAcc.Id; employeePoco.CreateDate = DateTime.Now; employeePoco.CreatedBy = sessionData.UserId; var employeeId = _employeeLogic.Add(employeePoco).Id; if (employeeId > 0) { scope.Complete(); result = employeeId.ToString(); } } } } } } catch (Exception ex) { } return(Json(result)); }
public IActionResult Add([FromBody] dynamic employeeLoanData) { ValidateSession(); var result = ""; try { if (employeeLoanData != null) { Lms_EmployeeLoanPoco employeeLoanPoco = JsonConvert.DeserializeObject <Lms_EmployeeLoanPoco>(JsonConvert.SerializeObject(employeeLoanData[0])); if (employeeLoanPoco.LoanAmount > 0) { using (var scope = new TransactionScope()) { var _transactionController = new TransactionController(_cache, _dbContext); var _configLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); var configInfo = _configLogic.GetSingleById(1); var employeeInfo = _employeeLogic.GetSingleById(employeeLoanPoco.EmployeeId); List <TransactionModel> debitTransactionModelList = new List <TransactionModel>(); TransactionModel debitTransactionModel = new TransactionModel(); debitTransactionModel.AccountId = employeeInfo.AccountId; debitTransactionModel.TxnAmount = employeeLoanPoco.LoanAmount; debitTransactionModelList.Add(debitTransactionModel); List <TransactionModel> creditTransactionModelList = new List <TransactionModel>(); TransactionModel creditTransactionModel = new TransactionModel(); creditTransactionModel.AccountId = (int)configInfo.LoanIncomeAccount; creditTransactionModel.TxnAmount = employeeLoanPoco.LoanAmount; creditTransactionModelList.Add(creditTransactionModel); var txnId = _transactionController.MakeTransaction(debitTransactionModelList, creditTransactionModelList, employeeLoanPoco.LoanAmount, DateTime.Now, DateTime.Now, employeeLoanPoco.Remarks); employeeLoanPoco.TransactionId = txnId; employeeLoanPoco.CreatedBy = sessionData.UserId; var loanId = _employeeLoanLogic.Add(employeeLoanPoco); if (!string.IsNullOrEmpty(loanId.ToString())) { result = loanId.ToString(); scope.Complete(); } } } } } catch (Exception ex) { } return(Json(result)); }
public IActionResult Index() { ValidateSession(); _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); ViewBag.DefaultFuelSurcharge = _configurationLogic.GetSingleById(1).DefaultFuelSurcharge; _cityLogic = new App_CityLogic(_cache, new EntityFrameworkGenericRepository <App_CityPoco>(_dbContext)); ViewBag.Cities = _cityLogic.GetList(); _provinceLogic = new App_ProvinceLogic(_cache, new EntityFrameworkGenericRepository <App_ProvincePoco>(_dbContext)); ViewBag.Provinces = _provinceLogic.GetList(); _countryLogic = new App_CountryLogic(_cache, new EntityFrameworkGenericRepository <App_CountryPoco>(_dbContext)); ViewBag.Countries = _countryLogic.GetList(); return(View(GetCustomerData(0))); }
public JsonResult GetCustomerById(string id) { if (!string.IsNullOrEmpty(id)) { var customer = _customerLogic.GetSingleById(Convert.ToInt32(id)); if (customer != null) { if (customer.FuelSurChargePercentage == null || customer.FuelSurChargePercentage <= 0) { _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); var defaultFuelSurcharge = _configurationLogic.GetSingleById(1).DefaultFuelSurcharge; customer.FuelSurChargePercentage = defaultFuelSurcharge; } return(Json(JsonConvert.SerializeObject(customer))); } } return(Json(string.Empty)); }
private ViewModel_MiscellaneousOrder GetMiscellaneousOrders() { ViewModel_MiscellaneousOrder miscOrderViewModel = new ViewModel_MiscellaneousOrder(); _cityLogic = new App_CityLogic(_cache, new EntityFrameworkGenericRepository <App_CityPoco>(_dbContext)); miscOrderViewModel.Cities = _cityLogic.GetList(); _provinceLogic = new App_ProvinceLogic(_cache, new EntityFrameworkGenericRepository <App_ProvincePoco>(_dbContext)); miscOrderViewModel.Provinces = _provinceLogic.GetList(); _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); miscOrderViewModel.Configuration = _configurationLogic.GetList().FirstOrDefault(); _customerLogic = new Lms_CustomerLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerPoco>(_dbContext)); miscOrderViewModel.Customers = _customerLogic.GetList(); _deliveryOptionLogic = new Lms_DeliveryOptionLogic(_cache, new EntityFrameworkGenericRepository <Lms_DeliveryOptionPoco>(_dbContext)); miscOrderViewModel.DeliveryOptions = _deliveryOptionLogic.GetList(); _unitTypeLogic = new Lms_UnitTypeLogic(_cache, new EntityFrameworkGenericRepository <Lms_UnitTypePoco>(_dbContext)); miscOrderViewModel.UnitTypes = _unitTypeLogic.GetList(); _weightScaleLogic = new Lms_WeightScaleLogic(_cache, new EntityFrameworkGenericRepository <Lms_WeightScalePoco>(_dbContext)); miscOrderViewModel.WeightScales = _weightScaleLogic.GetList(); _additionalServiceLogic = new Lms_AdditionalServiceLogic(_cache, new EntityFrameworkGenericRepository <Lms_AdditionalServicePoco>(_dbContext)); miscOrderViewModel.AdditionalServices = _additionalServiceLogic.GetList(); _employeeLogic = new Lms_EmployeeLogic(_cache, new EntityFrameworkGenericRepository <Lms_EmployeePoco>(_dbContext)); miscOrderViewModel.Employees = _employeeLogic.GetList().Where(c => c.EmployeeTypeId == 5).ToList(); // Load employees 'Broker' var orders = _orderLogic.GetList().Where(c => c.OrderTypeId == 3).ToList(); // Load only misc. orders List <ViewModel_OrderDispatched> viewModelOrders = new List <ViewModel_OrderDispatched>(); foreach (var item in orders) { ViewModel_OrderDispatched viewModelOrder = new ViewModel_OrderDispatched(); viewModelOrder.OrderId = item.Id; viewModelOrder.OrderTypeId = item.OrderTypeId; viewModelOrder.OrderTypeFlag = "Misc."; viewModelOrder.ServiceProviderEmployeeId = item.ServiceProviderEmployeeId; if (item.ServiceProviderEmployeeId != null && item.ServiceProviderEmployeeId > 0) { viewModelOrder.ServiceProviderEmployeeName = (miscOrderViewModel.Employees.Where(c => c.Id == item.ServiceProviderEmployeeId).FirstOrDefault()).FirstName; } viewModelOrder.WayBillNumber = item.WayBillNumber; viewModelOrder.OrderDateString = item.CreateDate.ToString("dd-MMM-yy"); viewModelOrder.CustomerRefNumber = item.ReferenceNumber; viewModelOrder.UnitTypeId = item.UnitTypeId; if (item.UnitTypeId > 0) { viewModelOrder.UnitTypeName = miscOrderViewModel.UnitTypes.Where(c => c.Id == viewModelOrder.UnitTypeId).FirstOrDefault().ShortCode; } viewModelOrder.UnitQuantity = item.UnitQuantity; viewModelOrder.SkidQuantity = item.SkidQuantity; viewModelOrder.TotalPiece = item.TotalPiece; viewModelOrder.SpcIns = ""; viewModelOrder.BillerCustomerId = item.BillToCustomerId; if (item.BillToCustomerId > 0) { viewModelOrder.BillerCustomerName = miscOrderViewModel.Customers.Where(c => c.Id == viewModelOrder.BillerCustomerId).FirstOrDefault().CustomerName; } viewModelOrders.Add(viewModelOrder); } miscOrderViewModel.MiscellaneousOrders = viewModelOrders; return(miscOrderViewModel); }
public IActionResult Add([FromBody] dynamic customerData) { ValidateSession(); var result = ""; try { if (customerData != null) { Lms_CustomerPoco customerPoco = JsonConvert.DeserializeObject <Lms_CustomerPoco>(JsonConvert.SerializeObject(customerData[0])); CustomerAddressMapping customerAddress = JsonConvert.DeserializeObject <CustomerAddressMapping>(JsonConvert.SerializeObject(customerData[1])); _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext)); var parentGLForCustomerAccount = _configurationLogic.GetSingleById(1).ParentGLForCustomerAccount; var accounts = _chartOfAccountLogic.GetList().Where(c => c.ParentGLCode == parentGLForCustomerAccount).ToList(); var newAccountId = accounts.Max(c => c.Id) + 1; var newCustomerId = _customerLogic.GetMaxId() + 1; using (var scope = new TransactionScope()) { Lms_ChartOfAccountPoco accountPoco = new Lms_ChartOfAccountPoco(); accountPoco.Id = newAccountId; accountPoco.ParentGLCode = parentGLForCustomerAccount; accountPoco.AccountName = customerPoco.CustomerName; accountPoco.BranchId = sessionData.BranchId == null ? 1 : (int)sessionData.BranchId; accountPoco.CurrentBalance = 0; accountPoco.IsActive = true; accountPoco.Remarks = "Customer Account Receivable"; accountPoco.CreateDate = DateTime.Now; accountPoco.CreatedBy = sessionData.UserId; var addedAcc = _chartOfAccountLogic.Add(accountPoco); if (addedAcc.Id > 0) { customerPoco.Id = newCustomerId; customerPoco.AccountId = addedAcc.Id; customerPoco.CreateDate = DateTime.Now; customerPoco.CreatedBy = sessionData.UserId; var customerId = _customerLogic.Add(customerPoco).Id; result = customerId.ToString(); } if (customerAddress != null && !string.IsNullOrEmpty(customerAddress.AddressLine)) { customerAddress.CustomerId = newCustomerId; customerAddress.IsDefault = true; _addressLogic = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext)); var addressList = _addressLogic.GetList(); _customerAddressMappingLogic = new Lms_CustomerAddressMappingLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerAddressMappingPoco>(_dbContext)); var customerAddressList = _customerAddressMappingLogic.GetList().Where(c => c.CustomerId == customerAddress.CustomerId); int addressId = 0; var existingAddress = addressList.Where(c => c.UnitNumber == customerAddress.UnitNumber && c.AddressLine == customerAddress.AddressLine && c.CityId == customerAddress.CityId).FirstOrDefault(); if (existingAddress != null) { existingAddress.ProvinceId = customerAddress.ProvinceId; existingAddress.CountryId = customerAddress.CountryId; existingAddress.PostCode = customerAddress.PostCode; existingAddress.PrimaryPhoneNumber = customerAddress.PrimaryPhoneNumber; existingAddress.Fax = customerAddress.Fax; existingAddress.EmailAddress1 = customerAddress.EmailAddress1; existingAddress.EmailAddress2 = customerAddress.EmailAddress1; existingAddress.ContactPersonName = customerAddress.ContactPersonName; addressId = _addressLogic.Update(existingAddress).Id; } else { Lms_AddressPoco addressPoco = new Lms_AddressPoco(); addressPoco.UnitNumber = customerAddress.UnitNumber; addressPoco.AddressLine = customerAddress.AddressLine; addressPoco.CityId = customerAddress.CityId; addressPoco.ProvinceId = customerAddress.ProvinceId; addressPoco.CountryId = customerAddress.CountryId; addressPoco.PostCode = customerAddress.PostCode; addressPoco.PrimaryPhoneNumber = customerAddress.PrimaryPhoneNumber; addressPoco.Fax = customerAddress.Fax; addressPoco.EmailAddress1 = customerAddress.EmailAddress1; addressPoco.EmailAddress2 = customerAddress.EmailAddress1; addressPoco.ContactPersonName = customerAddress.ContactPersonName; addressId = _addressLogic.Add(addressPoco).Id; } if (customerAddress.AddressTypeId == 0) { Lms_CustomerAddressMappingPoco customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); customerAddressMappingPoco.CustomerId = customerAddress.CustomerId; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Billing; customerAddressMappingPoco.IsDefault = customerAddress.IsDefault; _customerAddressMappingLogic.Add(customerAddressMappingPoco); customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); customerAddressMappingPoco.CustomerId = customerAddress.CustomerId; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Shipping; customerAddressMappingPoco.IsDefault = customerAddress.IsDefault; _customerAddressMappingLogic.Add(customerAddressMappingPoco); } else { Lms_CustomerAddressMappingPoco customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); customerAddressMappingPoco.CustomerId = customerAddress.CustomerId; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.AddressTypeId = customerAddress.AddressTypeId; customerAddressMappingPoco.IsDefault = customerAddress.IsDefault; _customerAddressMappingLogic.Add(customerAddressMappingPoco); } } scope.Complete(); } } } catch (Exception ex) { } return(Json(result)); }
public IActionResult Update([FromBody] dynamic customerData) { ValidateSession(); var result = ""; try { if (customerData != null) { Lms_CustomerPoco customerPoco = JsonConvert.DeserializeObject <Lms_CustomerPoco>(JsonConvert.SerializeObject(customerData[0])); CustomerAddressMapping customerAddress = JsonConvert.DeserializeObject <CustomerAddressMapping>(JsonConvert.SerializeObject(customerData[1])); _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); _chartOfAccountLogic = new Lms_ChartOfAccountLogic(_cache, new EntityFrameworkGenericRepository <Lms_ChartOfAccountPoco>(_dbContext)); var jAddressObject = (JObject)customerData[1]; var shippingAddressMappingId = Convert.ToString(jAddressObject.SelectToken("shippingAddressMappingId")); var billingAddressMappingId = Convert.ToString(jAddressObject.SelectToken("billingAddressMappingId")); //using (var scope = new TransactionScope()) //{ if (customerPoco.Id > 0) { var customer = _customerLogic.GetSingleById(customerPoco.Id); customer.CustomerName = customerPoco.CustomerName; customer.DiscountPercentage = customerPoco.DiscountPercentage; customer.FuelSurChargePercentage = customerPoco.FuelSurChargePercentage > 0 ? customerPoco.FuelSurChargePercentage : null; customer.InvoiceDueDays = customerPoco.InvoiceDueDays; customer.IsGstApplicable = customerPoco.IsGstApplicable; customer.IsActive = customerPoco.IsActive; var accountInfo = _chartOfAccountLogic.GetSingleById(customer.AccountId); accountInfo.AccountName = customerPoco.CustomerName; _chartOfAccountLogic.Update(accountInfo); result = _customerLogic.Update(customer).Id.ToString(); if (customerAddress != null) { customerAddress.CustomerId = customerPoco.Id; customerAddress.IsDefault = true; _addressLogic = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext)); var addressList = _addressLogic.GetList(); _customerAddressMappingLogic = new Lms_CustomerAddressMappingLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerAddressMappingPoco>(_dbContext)); var customerAddressList = _customerAddressMappingLogic.GetList().Where(c => c.CustomerId == customerAddress.CustomerId); int addressId = 0; var existingAddress = addressList.Where(c => c.UnitNumber == customerAddress.UnitNumber && c.AddressLine == customerAddress.AddressLine && c.CityId == customerAddress.CityId).ToList().FirstOrDefault(); if (existingAddress != null) { existingAddress.ProvinceId = customerAddress.ProvinceId; existingAddress.CountryId = customerAddress.CountryId; existingAddress.PostCode = customerAddress.PostCode; existingAddress.PrimaryPhoneNumber = customerAddress.PrimaryPhoneNumber; existingAddress.Fax = customerAddress.Fax; existingAddress.EmailAddress1 = customerAddress.EmailAddress1; existingAddress.EmailAddress2 = customerAddress.EmailAddress1; existingAddress.ContactPersonName = customerAddress.ContactPersonName; addressId = _addressLogic.Update(existingAddress).Id; } else { Lms_AddressPoco addressPoco = new Lms_AddressPoco(); addressPoco.UnitNumber = customerAddress.UnitNumber; addressPoco.AddressLine = customerAddress.AddressLine; addressPoco.CityId = customerAddress.CityId; addressPoco.ProvinceId = customerAddress.ProvinceId; addressPoco.CountryId = customerAddress.CountryId; addressPoco.PostCode = customerAddress.PostCode; addressPoco.PrimaryPhoneNumber = customerAddress.PrimaryPhoneNumber; addressPoco.Fax = customerAddress.Fax; addressPoco.EmailAddress1 = customerAddress.EmailAddress1; addressPoco.EmailAddress2 = customerAddress.EmailAddress1; addressPoco.ContactPersonName = customerAddress.ContactPersonName; addressId = _addressLogic.Add(addressPoco).Id; } // This will ensure only one address is set as default address for the same type var typeWiseAddresses = new List <Lms_CustomerAddressMappingPoco>(); if (customerAddress.IsDefault) { typeWiseAddresses = customerAddressList.Where(c => c.CustomerId == customerAddress.CustomerId && c.AddressTypeId == customerAddress.AddressTypeId).ToList(); if (typeWiseAddresses.Count > 0) { foreach (var item in typeWiseAddresses) { item.IsDefault = false; _customerAddressMappingLogic.Update(item); } } } var addressMappingList = _customerAddressMappingLogic.GetList(); if (customerAddress.AddressTypeId == 0) { Lms_CustomerAddressMappingPoco customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); if (billingAddressMappingId != "") { customerAddressMappingPoco = addressMappingList.Where(c => c.Id == Convert.ToInt32(billingAddressMappingId)).FirstOrDefault(); customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Billing; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.IsDefault = true; _customerAddressMappingLogic.Update(customerAddressMappingPoco); } else { customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); customerAddressMappingPoco.CustomerId = customerAddress.CustomerId; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Billing; customerAddressMappingPoco.IsDefault = true; _customerAddressMappingLogic.Add(customerAddressMappingPoco); } if (shippingAddressMappingId != "") { customerAddressMappingPoco = addressMappingList.Where(c => c.Id == Convert.ToInt32(shippingAddressMappingId)).FirstOrDefault(); customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Shipping; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.IsDefault = true; _customerAddressMappingLogic.Update(customerAddressMappingPoco); } else { customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); customerAddressMappingPoco.CustomerId = customerAddress.CustomerId; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.AddressTypeId = (byte)Enum_AddressType.Shipping; customerAddressMappingPoco.IsDefault = true; _customerAddressMappingLogic.Add(customerAddressMappingPoco); } } else { Lms_CustomerAddressMappingPoco customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); if (customerAddress.AddressTypeId == 1) { if (billingAddressMappingId != "") { customerAddressMappingPoco = addressMappingList.Where(c => c.Id == Convert.ToInt32(billingAddressMappingId)).FirstOrDefault(); customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.IsDefault = true; _customerAddressMappingLogic.Update(customerAddressMappingPoco); } else { customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); customerAddressMappingPoco.CustomerId = customerAddress.CustomerId; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.AddressTypeId = customerAddress.AddressTypeId; customerAddressMappingPoco.IsDefault = true; _customerAddressMappingLogic.Add(customerAddressMappingPoco); } } if (customerAddress.AddressTypeId == 2) { if (shippingAddressMappingId != "") { customerAddressMappingPoco = addressMappingList.Where(c => c.Id == Convert.ToInt32(shippingAddressMappingId)).FirstOrDefault(); customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.IsDefault = true; _customerAddressMappingLogic.Update(customerAddressMappingPoco); } else { customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco(); customerAddressMappingPoco.CustomerId = customerAddress.CustomerId; customerAddressMappingPoco.AddressId = addressId; customerAddressMappingPoco.AddressTypeId = customerAddress.AddressTypeId; customerAddressMappingPoco.IsDefault = true; _customerAddressMappingLogic.Add(customerAddressMappingPoco); } } } } //scope.Complete(); } //} } } catch (Exception ex) { } return(Json(result)); }
public IActionResult Add([FromBody] dynamic orderData) { ValidateSession(); var result = ""; string newWaybillNumber = ""; var waybillPrefix = ""; try { if (orderData != null) { using (var scope = new TransactionScope()) { Lms_OrderPoco orderPoco = JsonConvert.DeserializeObject <Lms_OrderPoco>(JsonConvert.SerializeObject(orderData[0])); _addressLogic = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext)); _configurationLogic = new Lms_ConfigurationLogic(_cache, new EntityFrameworkGenericRepository <Lms_ConfigurationPoco>(_dbContext)); var configInfo = _configurationLogic.GetSingleById(1); var addressList = _addressLogic.GetList(); Lms_AddressPoco newAddress = new Lms_AddressPoco(); var orderAddressData = (JObject)orderData[0]; var customerId = orderAddressData.SelectToken("customerId").ToString(); var waybillNumber = orderAddressData.SelectToken("wayBillNumber").ToString(); var customerAddressId = orderAddressData.SelectToken("customerAddressId").ToString(); var customerAddressline = orderAddressData.SelectToken("customerAddressline").ToString(); var customerUnitNo = orderAddressData.SelectToken("customerUnitNo").ToString(); var customerCityId = orderAddressData.SelectToken("customerCityId").ToString(); var customerProvinceId = orderAddressData.SelectToken("customerProvinceId").ToString(); var customerPostcode = orderAddressData.SelectToken("customerPostcode").ToString(); var customerCountryId = orderAddressData.SelectToken("customerCountry").ToString(); var orderDate = orderAddressData.SelectToken("orderDate").ToString(); orderPoco.ShipperAddressId = customerAddressId == "" ? 0 : Convert.ToInt32(customerAddressId); orderPoco.ShipperCustomerId = customerId == "" ? 0 : Convert.ToInt32(customerId); orderPoco.IsInvoiced = false; orderPoco.ScheduledPickupDate = orderDate == "" ? DateTime.Today : Convert.ToDateTime(orderDate); orderPoco.ExpectedDeliveryDate = orderDate == "" ? DateTime.Today : Convert.ToDateTime(orderDate); orderPoco.CreateDate = Convert.ToDateTime(DateTime.Now.ToString("dd-MMM-yyyy")); orderPoco.CreatedBy = sessionData.UserId; orderPoco.OrderTypeId = 3; //3 for misc. order if (orderPoco.OrderShareAmount <= 0) { orderPoco.OrderShareAmount = null; orderPoco.IsSharingOnPercent = null; } newWaybillNumber = orderPoco.WayBillNumber; if (string.IsNullOrEmpty(newWaybillNumber) || Convert.ToInt32(newWaybillNumber) < 1) { var maxWaybillNumber = _orderLogic.GetList().Select(c => c.WayBillNumber).OrderByDescending(c => c).FirstOrDefault(); if (maxWaybillNumber != null) { newWaybillNumber = Convert.ToString(Convert.ToInt32(maxWaybillNumber) + 1); } else { newWaybillNumber = configInfo.DeliveryWBNoStartFrom; if (string.IsNullOrEmpty(newWaybillNumber)) { newWaybillNumber = "1"; } } waybillPrefix = configInfo.WayBillPrefix; newWaybillNumber = waybillPrefix + newWaybillNumber; } orderPoco.WayBillNumber = newWaybillNumber; newAddress = new Lms_AddressPoco(); newAddress.AddressLine = customerAddressline.Trim().ToUpper(); newAddress.UnitNumber = customerUnitNo.Trim().ToUpper(); newAddress.CityId = Convert.ToInt16(customerCityId); newAddress.ProvinceId = Convert.ToInt16(customerProvinceId); newAddress.CountryId = Convert.ToInt16(customerCountryId); // default Canada newAddress.PostCode = customerPostcode.Trim().ToUpper(); newAddress.CreatedBy = sessionData.UserId; var customerAddressInfo = addressList.Where(c => c.AddressLine == newAddress.AddressLine && c.CityId == newAddress.CityId && c.ProvinceId == newAddress.ProvinceId).FirstOrDefault(); if (customerAddressInfo != null) { if (string.IsNullOrEmpty(newAddress.UnitNumber)) { newAddress.UnitNumber = null; } if (string.IsNullOrEmpty(customerAddressInfo.UnitNumber)) { customerAddressInfo.UnitNumber = null; } if (customerAddressInfo.UnitNumber != newAddress.UnitNumber) { customerAddressInfo = null; } } if (customerAddressInfo != null) { if (customerAddressline.Trim().ToUpper() == customerAddressInfo.AddressLine.Trim().ToUpper() && customerUnitNo.Trim().ToUpper() == customerAddressInfo.UnitNumber && Convert.ToInt16(customerCityId) == customerAddressInfo.CityId) { if (Convert.ToInt16(customerProvinceId) != customerAddressInfo.ProvinceId || customerPostcode != customerAddressInfo.PostCode) { customerAddressInfo.ProvinceId = Convert.ToInt16(customerProvinceId); customerAddressInfo.PostCode = customerPostcode; customerAddressInfo.CountryId = Convert.ToInt16(customerCountryId); orderPoco.ShipperAddressId = _addressLogic.Update(customerAddressInfo).Id; } } else { orderPoco.ShipperAddressId = _addressLogic.Add(newAddress).Id; } } else { orderPoco.ShipperAddressId = _addressLogic.Add(newAddress).Id; } List <Lms_OrderAdditionalServicePoco> orderAdditionalServices = JsonConvert.DeserializeObject <List <Lms_OrderAdditionalServicePoco> >(JsonConvert.SerializeObject(orderData[1])); _orderAdditionalServiceLogic = new Lms_OrderAdditionalServiceLogic(_cache, new EntityFrameworkGenericRepository <Lms_OrderAdditionalServicePoco>(_dbContext)); if (orderPoco.Id < 1 && orderPoco.BillToCustomerId > 0) { var addedOrder = _orderLogic.Add(orderPoco); foreach (var item in orderAdditionalServices) { item.OrderId = addedOrder.Id; var existingRecord = _orderAdditionalServiceLogic.GetList().Where(c => c.OrderId == addedOrder.Id && c.AdditionalServiceId == item.AdditionalServiceId).FirstOrDefault(); if (existingRecord == null) { _orderAdditionalServiceLogic.Add(item); } else { _orderAdditionalServiceLogic.Remove(existingRecord); _orderAdditionalServiceLogic.Add(item); } } result = addedOrder.WayBillNumber; } if (result != "") { scope.Complete(); } } } } catch (Exception ex) { } return(Json(result)); }