예제 #1
0
        private List <ViewModel_CustomerAddress> GetCustomerAddressData(int id)
        {
            List <ViewModel_CustomerAddress> customerAddressViewModel = new List <ViewModel_CustomerAddress>();

            _customerAddressLogic = new Lms_CustomerAddressMappingLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerAddressMappingPoco>(_dbContext));
            var customerAddresses = _customerAddressLogic.GetList().Where(c => c.CustomerId == id).ToList();

            _cityLogic = new App_CityLogic(_cache, new EntityFrameworkGenericRepository <App_CityPoco>(_dbContext));
            var cities = _cityLogic.GetList();

            _provinceLogic = new App_ProvinceLogic(_cache, new EntityFrameworkGenericRepository <App_ProvincePoco>(_dbContext));
            var provinces = _provinceLogic.GetList();

            _countryLogic = new App_CountryLogic(_cache, new EntityFrameworkGenericRepository <App_CountryPoco>(_dbContext));
            var countries = _countryLogic.GetList();

            _addressLogic = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext));
            var addresses = _addressLogic.GetList();

            foreach (var custAddress in customerAddresses)
            {
                ViewModel_CustomerAddress customerAddress = new ViewModel_CustomerAddress();

                var address = addresses.Where(c => c.Id == custAddress.AddressId).FirstOrDefault();
                customerAddress.CustomerId      = custAddress.CustomerId;
                customerAddress.AddressId       = custAddress.AddressId;
                customerAddress.AddressTypeId   = custAddress.AddressTypeId;
                customerAddress.AddressTypeName = customerAddress.AddressTypeId == 1 ? "Billing" : customerAddress.AddressTypeId == 2 ? "Shipping" : customerAddress.AddressTypeId == 4 ? "Warehouse" : "";

                customerAddress.IsDefault = custAddress.IsDefault;

                customerAddress.UnitNumber   = address.UnitNumber;
                customerAddress.HouseNumber  = address.HouseNumber;
                customerAddress.AddressLine  = address.AddressLine;
                customerAddress.CityId       = address.CityId;
                customerAddress.CityName     = cities.Where(c => c.Id == address.CityId).FirstOrDefault().CityName;
                customerAddress.ProvinceId   = address.ProvinceId;
                customerAddress.ProvinceName = provinces.Where(c => c.Id == address.ProvinceId).FirstOrDefault().ShortCode;
                customerAddress.CountryId    = address.CountryId;
                customerAddress.CountryName  = countries.Where(c => c.Id == address.CountryId).FirstOrDefault().CountryName;
                customerAddress.PostCode     = address.PostCode;

                customerAddress.MergedAddressLine  = !string.IsNullOrEmpty(customerAddress.UnitNumber) ? customerAddress.UnitNumber + ", " : customerAddress.UnitNumber;
                customerAddress.MergedAddressLine += !string.IsNullOrEmpty(customerAddress.AddressLine) ? customerAddress.AddressLine + ", " : customerAddress.AddressLine;
                customerAddress.MergedAddressLine += customerAddress.CityName + ", " + customerAddress.ProvinceName + ", " + customerAddress.CountryName;
                customerAddress.MergedAddressLine += !string.IsNullOrEmpty(customerAddress.PostCode) ? ", " + customerAddress.PostCode : customerAddress.PostCode;

                customerAddress.Email         = address.EmailAddress1;
                customerAddress.Phone         = address.PrimaryPhoneNumber;
                customerAddress.Fax           = address.Fax;
                customerAddress.ContactPerson = address.ContactPersonName;

                customerAddressViewModel.Add(customerAddress);
            }


            return(customerAddressViewModel);
        }
 public AddressController(IMemoryCache cache, LogisticsContext dbContext)
 {
     _cache         = cache;
     _dbContext     = dbContext;
     _addressLogic  = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext));
     _cityLogic     = new App_CityLogic(_cache, new EntityFrameworkGenericRepository <App_CityPoco>(_dbContext));
     _provinceLogic = new App_ProvinceLogic(_cache, new EntityFrameworkGenericRepository <App_ProvincePoco>(_dbContext));
     _countryLogic  = new App_CountryLogic(_cache, new EntityFrameworkGenericRepository <App_CountryPoco>(_dbContext));
 }
예제 #3
0
        /// <summary>
        /// This method is used to retrive existing address from Address table or Add new address if doesn't exist. Returns addressId. Address should not be updated from this method
        /// </summary>
        /// <param name="customerAddress"></param>
        /// <returns></returns>
        private int AddOrGetAddress(CustomerAddress customerAddress)
        {
            if (string.IsNullOrEmpty(customerAddress.AddressLine) || customerAddress.CityId < 1)
            {
                return(0);
            }

            int addressId = 0;

            _addressLogic = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext));
            var addressList = _addressLogic.GetList();

            string unitNumber  = "";
            string addressLine = "";

            unitNumber  = !string.IsNullOrEmpty(customerAddress.AddressUnitNumber.Trim()) ? customerAddress.AddressUnitNumber.Trim().ToUpper() : null;
            addressLine = !string.IsNullOrEmpty(customerAddress.AddressLine.Trim()) ? customerAddress.AddressLine.Trim().ToUpper() : null;

            var existingBillingAddress = addressList.Where(c => c.UnitNumber == unitNumber && c.AddressLine == addressLine && c.CityId == customerAddress.CityId).FirstOrDefault();

            if (existingBillingAddress == null)
            {
                Lms_AddressPoco addressPoco = new Lms_AddressPoco();
                addressPoco.UnitNumber         = unitNumber;
                addressPoco.AddressLine        = 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.EmailAddress;
                addressPoco.EmailAddress2     = customerAddress.EmailAddress;
                addressPoco.ContactPersonName = customerAddress.ContactPersonName;

                addressId = _addressLogic.Add(addressPoco).Id;
            }
            else
            {
                existingBillingAddress.ProvinceId         = customerAddress.ProvinceId;
                existingBillingAddress.CountryId          = customerAddress.CountryId;
                existingBillingAddress.PostCode           = customerAddress.PostCode;
                existingBillingAddress.PrimaryPhoneNumber = customerAddress.PrimaryPhoneNumber;
                existingBillingAddress.Fax               = customerAddress.Fax;
                existingBillingAddress.EmailAddress1     = customerAddress.EmailAddress;
                existingBillingAddress.EmailAddress2     = customerAddress.EmailAddress;
                existingBillingAddress.ContactPersonName = customerAddress.ContactPersonName;

                addressId = _addressLogic.Update(existingBillingAddress).Id;
            }

            return(addressId);
        }
        public ReportController(IMemoryCache cache, IHostingEnvironment hostingEnvironment, IHttpContextAccessor httpContext, LogisticsContext dbContext)
        {
            _dbContext          = dbContext;
            _cache              = cache;
            _hostingEnvironment = hostingEnvironment;
            _httpContext        = httpContext;

            _orderLogic             = new Lms_OrderLogic(_cache, new EntityFrameworkGenericRepository <Lms_OrderPoco>(_dbContext));
            _customerLogic          = new Lms_CustomerLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerPoco>(_dbContext));
            _addressMappingLogic    = new Lms_CustomerAddressMappingLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerAddressMappingPoco>(_dbContext));
            _addressLogic           = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext));
            _invoiceLogic           = new Lms_InvoiceLogic(_cache, new EntityFrameworkGenericRepository <Lms_InvoicePoco>(_dbContext));
            _additionalServiceLogic = new Lms_OrderAdditionalServiceLogic(_cache, new EntityFrameworkGenericRepository <Lms_OrderAdditionalServicePoco>(_dbContext));
            _paymentMethodLogic     = new Lms_PaymentMethodLogic(_cache, new EntityFrameworkGenericRepository <Lms_PaymentMethodPoco>(_dbContext));
            _paymentCollectionLogic = new Lms_InvoicePaymentCollectionLogic(_cache, new EntityFrameworkGenericRepository <Lms_InvoicePaymentCollectionPoco>(_dbContext));

            _cityLogic     = new App_CityLogic(_cache, new EntityFrameworkGenericRepository <App_CityPoco>(_dbContext));
            _provinceLogic = new App_ProvinceLogic(_cache, new EntityFrameworkGenericRepository <App_ProvincePoco>(_dbContext));
            _countryLogic  = new App_CountryLogic(_cache, new EntityFrameworkGenericRepository <App_CountryPoco>(_dbContext));
            _bankLogic     = new Lms_BankLogic(_cache, new EntityFrameworkGenericRepository <Lms_BankPoco>(_dbContext));
        }
        public SearchController(IMemoryCache cache, IEmailService emailService, IHostingEnvironment hostingEnvironment, IHttpContextAccessor httpContext, LogisticsContext dbContext)
        {
            _cache              = cache;
            _dbContext          = dbContext;
            _emailService       = emailService;
            _hostingEnvironment = hostingEnvironment;
            _httpContext        = httpContext;

            _orderLogic    = new Lms_OrderLogic(_cache, new EntityFrameworkGenericRepository <Lms_OrderPoco>(_dbContext));
            _customerLogic = new Lms_CustomerLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerPoco>(_dbContext));
            _addressLogic  = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext));
            _employeeLogic = new Lms_EmployeeLogic(_cache, new EntityFrameworkGenericRepository <Lms_EmployeePoco>(_dbContext));

            _cityLogic     = new App_CityLogic(_cache, new EntityFrameworkGenericRepository <App_CityPoco>(_dbContext));
            _provinceLogic = new App_ProvinceLogic(_cache, new EntityFrameworkGenericRepository <App_ProvincePoco>(_dbContext));
            _countryLogic  = new App_CountryLogic(_cache, new EntityFrameworkGenericRepository <App_CountryPoco>(_dbContext));

            _unitTypeLogic    = new Lms_UnitTypeLogic(_cache, new EntityFrameworkGenericRepository <Lms_UnitTypePoco>(_dbContext));
            _weightScaleLogic = new Lms_WeightScaleLogic(_cache, new EntityFrameworkGenericRepository <Lms_WeightScalePoco>(_dbContext));

            _deliveryOptionLogic   = new Lms_DeliveryOptionLogic(_cache, new EntityFrameworkGenericRepository <Lms_DeliveryOptionPoco>(_dbContext));
            _vehicleTypeScaleLogic = new Lms_VehicleTypeLogic(_cache, new EntityFrameworkGenericRepository <Lms_VehicleTypePoco>(_dbContext));
        }
예제 #6
0
        public IActionResult Add([FromBody] dynamic orderData)
        {
            ValidateSession();
            var result = "";

            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));
                        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 orderDate           = orderAddressData.SelectToken("orderDate").ToString();
                        orderPoco.ShipperAddressId  = customerAddressId == "" ? 0 : Convert.ToInt32(customerAddressId);
                        orderPoco.ShipperCustomerId = customerId == "" ? 0 : Convert.ToInt32(customerId);
                        orderPoco.IsInvoiced        = false;
                        orderPoco.CreateDate        = orderDate == "" ? DateTime.Today : Convert.ToDateTime(orderDate);
                        orderPoco.CreatedBy         = sessionData.UserId;
                        orderPoco.OrderTypeId       = 3; //3 for misc. order
                        var newWbNumber = _orderLogic.GetList().OrderByDescending(c => c.WayBillNumber).Take(1).FirstOrDefault().WayBillNumber;
                        if (!(newWbNumber.Length > 0))
                        {
                            newWbNumber = _configurationLogic.GetSingleById(1).DeliveryWBNoStartFrom;
                        }
                        else
                        {
                            newWbNumber = (Convert.ToInt16(newWbNumber) + 1).ToString();
                        }

                        orderPoco.WayBillNumber = newWbNumber;

                        var customerAddressInfo = addressList.Where(c => c.Id == orderPoco.ShipperAddressId).FirstOrDefault();
                        if (customerAddressInfo != null)
                        {
                            customerAddressInfo.UnitNumber = !string.IsNullOrEmpty(customerAddressInfo.UnitNumber) ? Convert.ToString(customerAddressInfo.UnitNumber).Trim().ToUpper() : "";
                            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;
                                    _addressLogic.Update(customerAddressInfo);
                                }
                            }
                            else
                            {
                                newAddress                 = new Lms_AddressPoco();
                                newAddress.AddressLine     = customerAddressline;
                                newAddress.UnitNumber      = customerUnitNo;
                                newAddress.CityId          = Convert.ToInt16(customerCityId);
                                newAddress.ProvinceId      = Convert.ToInt16(customerProvinceId);
                                newAddress.CountryId       = 41; // default Canada
                                newAddress.PostCode        = customerPostcode;
                                newAddress.CreatedBy       = sessionData.UserId;
                                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));
        }
예제 #7
0
        public JsonResult PrintWaybill([FromBody] dynamic orderData)
        {
            try
            {
                List <ViewModel_PrintWaybill> waybillPrintViewModels = new List <ViewModel_PrintWaybill>();
                JArray wayBillNumberList = null;

                var orderList = _orderLogic.GetList();

                _addressLogic = new Lms_AddressLogic(_cache, new EntityFrameworkGenericRepository <Lms_AddressPoco>(_dbContext));
                var addresses = _addressLogic.GetList();

                _cityLogic = new App_CityLogic(_cache, new EntityFrameworkGenericRepository <App_CityPoco>(_dbContext));
                var cities = _cityLogic.GetList();

                _provinceLogic = new App_ProvinceLogic(_cache, new EntityFrameworkGenericRepository <App_ProvincePoco>(_dbContext));
                var provinces = _provinceLogic.GetList();

                _customerLogic = new Lms_CustomerLogic(_cache, new EntityFrameworkGenericRepository <Lms_CustomerPoco>(_dbContext));
                var customers = _customerLogic.GetList();

                _deliveryOptionLogic = new Lms_DeliveryOptionLogic(_cache, new EntityFrameworkGenericRepository <Lms_DeliveryOptionPoco>(_dbContext));
                var deliveryOptions = _deliveryOptionLogic.GetList();

                _unitTypeLogic = new Lms_UnitTypeLogic(_cache, new EntityFrameworkGenericRepository <Lms_UnitTypePoco>(_dbContext));
                var unitTypes = _unitTypeLogic.GetList();

                _weightScaleLogic = new Lms_WeightScaleLogic(_cache, new EntityFrameworkGenericRepository <Lms_WeightScalePoco>(_dbContext));
                var weightScales = _weightScaleLogic.GetList();

                if (orderData != null)
                {
                    wayBillNumberList = JArray.Parse(JsonConvert.SerializeObject(orderData[0]));
                }

                foreach (var item in wayBillNumberList)
                {
                    var wbNumber  = item.ToString();
                    var orderInfo = orderList.Where(c => c.WayBillNumber == wbNumber && c.OrderTypeId == 1).FirstOrDefault(); //consider only the single order; not the return order
                    if (orderInfo != null)
                    {
                        ViewModel_PrintWaybill waybillPrintViewModel = new ViewModel_PrintWaybill();

                        waybillPrintViewModel.WaybillNumber           = orderInfo.WayBillNumber;
                        waybillPrintViewModel.WayBillDate             = orderInfo.CreateDate.ToString("dd-MMM-yy");
                        waybillPrintViewModel.BillerCustomerId        = orderInfo.BillToCustomerId;
                        waybillPrintViewModel.CustomerRefNo           = orderInfo.ReferenceNumber;
                        waybillPrintViewModel.CargoCtlNo              = orderInfo.CargoCtlNumber;
                        waybillPrintViewModel.AwbContainerNo          = orderInfo.AwbCtnNumber;
                        waybillPrintViewModel.BillerCustomerName      = customers.Where(c => c.Id == orderInfo.BillToCustomerId).FirstOrDefault().CustomerName;
                        waybillPrintViewModel.OrderedByName           = orderInfo.OrderedBy;
                        waybillPrintViewModel.DeliveryOptionShortCode = deliveryOptions.Where(c => c.Id == orderInfo.DeliveryOptionId).FirstOrDefault().ShortCode;

                        waybillPrintViewModel.OrderBasePrice = orderInfo.OrderBasicCost.ToString();
                        if (orderInfo.BasicCostOverriden != null && orderInfo.BasicCostOverriden > 0)
                        {
                            waybillPrintViewModel.OrderBasePrice = orderInfo.BasicCostOverriden.ToString();
                        }

                        if (orderInfo.DiscountPercentOnOrderCost != null && orderInfo.DiscountPercentOnOrderCost > 0)
                        {
                            var orderDiscount = Convert.ToDecimal(waybillPrintViewModel.OrderBasePrice) - (Convert.ToDecimal(waybillPrintViewModel.OrderBasePrice) * orderInfo.DiscountPercentOnOrderCost / 100);
                            if (orderDiscount > 0)
                            {
                                waybillPrintViewModel.OrderDiscountAmount = orderDiscount.ToString();
                                waybillPrintViewModel.OrderBasePrice      = (Convert.ToDecimal(waybillPrintViewModel.OrderBasePrice) - (decimal)orderDiscount).ToString();
                            }
                            else
                            {
                                waybillPrintViewModel.OrderDiscountAmount = "0.00";
                            }
                        }

                        if (orderInfo.FuelSurchargePercentage != null && orderInfo.FuelSurchargePercentage > 0)
                        {
                            var fuelAmnt = Convert.ToDecimal(waybillPrintViewModel.OrderBasePrice) * orderInfo.FuelSurchargePercentage / 100;
                            if (fuelAmnt > 0)
                            {
                                waybillPrintViewModel.FuelSurcharge = fuelAmnt.ToString();
                            }
                            else
                            {
                                waybillPrintViewModel.FuelSurcharge = "0.00";
                            }
                        }

                        if (orderInfo.TotalAdditionalServiceCost > 0)
                        {
                            waybillPrintViewModel.AdditionalServiceCost = orderInfo.TotalAdditionalServiceCost.ToString();
                        }
                        else
                        {
                            waybillPrintViewModel.AdditionalServiceCost = "0.00";
                        }

                        if (orderInfo.ApplicableGstPercent != null && orderInfo.ApplicableGstPercent > 0)
                        {
                            var taxAmnt = Convert.ToDecimal(waybillPrintViewModel.OrderBasePrice) * orderInfo.ApplicableGstPercent / 100;
                            if (taxAmnt > 0)
                            {
                                waybillPrintViewModel.OrderTaxAmountOnBasePrice = taxAmnt.ToString();
                            }
                            else
                            {
                                waybillPrintViewModel.OrderTaxAmountOnBasePrice = "0.00";
                            }
                        }

                        waybillPrintViewModel.NetTotalOrderCost   = (Convert.ToDecimal(waybillPrintViewModel.OrderBasePrice) + Convert.ToDecimal(waybillPrintViewModel.FuelSurcharge) + Convert.ToDecimal(waybillPrintViewModel.AdditionalServiceCost)).ToString();
                        waybillPrintViewModel.ShipperCustomerName = customers.Where(c => c.Id == orderInfo.ShipperCustomerId).FirstOrDefault().CustomerName;

                        var shippperAddress = addresses.Where(c => c.Id == orderInfo.ShipperAddressId).FirstOrDefault();

                        waybillPrintViewModel.ShipperCustomerAddressLine1 = !string.IsNullOrEmpty(shippperAddress.UnitNumber) ? shippperAddress.UnitNumber + ", " + shippperAddress.AddressLine : shippperAddress.AddressLine;
                        waybillPrintViewModel.ShipperCustomerAddressLine2 = cities.Where(c => c.Id == shippperAddress.CityId).FirstOrDefault().CityName + ", " + provinces.Where(c => c.Id == shippperAddress.ProvinceId).FirstOrDefault().ShortCode + "  " + shippperAddress.PostCode;

                        waybillPrintViewModel.ConsigneeCustomerName = customers.Where(c => c.Id == orderInfo.ConsigneeCustomerId).FirstOrDefault().CustomerName;

                        var consigneeAddress = addresses.Where(c => c.Id == orderInfo.ConsigneeAddressId).FirstOrDefault();


                        waybillPrintViewModel.ConsigneeCustomerAddressLine1 = !string.IsNullOrEmpty(consigneeAddress.UnitNumber) ? consigneeAddress.UnitNumber + ", " + consigneeAddress.AddressLine : consigneeAddress.AddressLine;
                        waybillPrintViewModel.ConsigneeCustomerAddressLine2 = cities.Where(c => c.Id == consigneeAddress.CityId).FirstOrDefault().CityName + ", " + provinces.Where(c => c.Id == consigneeAddress.ProvinceId).FirstOrDefault().ShortCode + "  " + consigneeAddress.PostCode;

                        waybillPrintViewModel.TotalSkidPieces      = 0;
                        waybillPrintViewModel.UnitTypeName         = unitTypes.Where(c => c.Id == orderInfo.UnitTypeId).FirstOrDefault().TypeName;
                        waybillPrintViewModel.UnitTypeShortCode    = unitTypes.Where(c => c.Id == orderInfo.UnitTypeId).FirstOrDefault().ShortCode;
                        waybillPrintViewModel.UnitQuantity         = orderInfo.UnitQuantity;
                        waybillPrintViewModel.WeightScaleShortCode = weightScales.Where(c => c.Id == orderInfo.WeightScaleId).FirstOrDefault().ShortCode;
                        waybillPrintViewModel.WeightTotal          = orderInfo.WeightTotal.ToString();
                        waybillPrintViewModel.DeliveryDate         = null;
                        waybillPrintViewModel.DeliveryTime         = null;
                        waybillPrintViewModel.PUDriverName         = "";
                        waybillPrintViewModel.DeliveryDriverName   = orderInfo.WayBillNumber;
                        if (orderInfo.IsPrintedOnWayBill != null && orderInfo.IsPrintedOnWayBill == true)
                        {
                            waybillPrintViewModel.WaybillComments = orderInfo.CommentsForWayBill;
                        }

                        waybillPrintViewModels.Add(waybillPrintViewModel);
                    }
                }

                var webrootPath = _hostingEnvironment.WebRootPath;
                var uniqueId    = DateTime.Now.ToFileTime();
                var path        = "/contents/waybills/waybill_" + uniqueId + ".pdf";
                var filePath    = webrootPath + path;

                var pdfReport = new ViewAsPdf("PrintWaybill", waybillPrintViewModels);
                var file      = pdfReport.BuildFile(ControllerContext).Result;

                System.IO.File.WriteAllBytes(filePath, file);

                //_emailService.SendEmail("*****@*****.**", "test subject", "test body content", path);


                return(Json(path));
            }
            catch (Exception ex)
            {
                return(null);
            }
            //return View();
        }
예제 #8
0
        public IActionResult Update([FromBody] dynamic orderData)
        {
            ValidateSession();
            var result = "";

            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));
                        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 orderDate           = orderAddressData.SelectToken("orderDate").ToString();
                        orderPoco.ShipperAddressId  = customerAddressId == "" ? 0 : Convert.ToInt32(customerAddressId);
                        orderPoco.ShipperCustomerId = customerId == "" ? 0 : Convert.ToInt32(customerId);
                        orderPoco.CreateDate        = orderDate == "" ? DateTime.Today : Convert.ToDateTime(orderDate);

                        var customerAddressInfo = addressList.Where(c => c.Id == orderPoco.ShipperAddressId).FirstOrDefault();
                        if (customerAddressInfo != null)
                        {
                            customerAddressInfo.UnitNumber = !string.IsNullOrEmpty(customerAddressInfo.UnitNumber) ? Convert.ToString(customerAddressInfo.UnitNumber).Trim().ToUpper() : "";
                            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;
                                    _addressLogic.Update(customerAddressInfo);
                                }
                            }
                            else
                            {
                                newAddress                 = new Lms_AddressPoco();
                                newAddress.AddressLine     = customerAddressline;
                                newAddress.UnitNumber      = customerUnitNo;
                                newAddress.CityId          = Convert.ToInt16(customerCityId);
                                newAddress.ProvinceId      = Convert.ToInt16(customerProvinceId);
                                newAddress.CountryId       = 41; // default Canada, UI have to change to accept country
                                newAddress.PostCode        = customerPostcode;
                                newAddress.CreatedBy       = sessionData.UserId;
                                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 > 0 && orderPoco.BillToCustomerId > 0)
                        {
                            var existingOrder = _orderLogic.GetSingleById(orderPoco.Id);
                            if (existingOrder != null)
                            {
                                existingOrder.CommentsForInvoice = orderPoco.CommentsForInvoice;
                                existingOrder.IsPrintedOnInvoice = orderPoco.IsPrintedOnInvoice;
                                existingOrder.IsPrintedOnWayBill = orderPoco.IsPrintedOnWayBill;
                                existingOrder.CommentsForWayBill = orderPoco.CommentsForWayBill;

                                existingOrder.OrderBasicCost             = orderPoco.OrderBasicCost;
                                existingOrder.DiscountPercentOnOrderCost = orderPoco.DiscountPercentOnOrderCost;
                                existingOrder.ApplicableGstPercent       = orderPoco.ApplicableGstPercent;
                                existingOrder.TotalOrderCost             = orderPoco.TotalOrderCost;
                                existingOrder.TotalAdditionalServiceCost = orderPoco.TotalAdditionalServiceCost;

                                existingOrder.BillToCustomerId          = orderPoco.BillToCustomerId;
                                existingOrder.ReferenceNumber           = orderPoco.ReferenceNumber;
                                existingOrder.AwbCtnNumber              = orderPoco.AwbCtnNumber;
                                existingOrder.CargoCtlNumber            = orderPoco.CargoCtlNumber;
                                existingOrder.CreateDate                = orderPoco.CreateDate;
                                existingOrder.OrderedBy                 = orderPoco.OrderedBy;
                                existingOrder.ContactPhoneNumber        = orderPoco.ContactPhoneNumber;
                                existingOrder.DepartmentName            = orderPoco.DepartmentName;
                                existingOrder.ShipperAddressId          = orderPoco.ShipperAddressId;
                                existingOrder.ShipperCustomerId         = orderPoco.ShipperCustomerId;
                                existingOrder.ServiceProviderEmployeeId = orderPoco.ServiceProviderEmployeeId;

                                existingOrder.UnitTypeId    = orderPoco.UnitTypeId;
                                existingOrder.UnitQuantity  = orderPoco.UnitQuantity;
                                existingOrder.SkidQuantity  = orderPoco.SkidQuantity;
                                existingOrder.TotalPiece    = orderPoco.TotalPiece;
                                existingOrder.WeightScaleId = orderPoco.WeightScaleId;
                                existingOrder.WeightTotal   = orderPoco.WeightTotal;
                                existingOrder.CityId        = orderPoco.CityId;

                                var orderServices = _orderAdditionalServiceLogic.GetList().Where(c => c.OrderId == existingOrder.Id).ToList();
                                if (orderServices.Count > 0)
                                {
                                    foreach (var item in orderServices)
                                    {
                                        _orderAdditionalServiceLogic.Remove(item);
                                    }
                                }

                                if (orderAdditionalServices.Count > 0)
                                {
                                    foreach (var item in orderAdditionalServices)
                                    {
                                        if (item.AdditionalServiceId > 0)
                                        {
                                            item.OrderId = existingOrder.Id;
                                            _orderAdditionalServiceLogic.Add(item);
                                        }
                                    }
                                }

                                var updatedOrder = _orderLogic.Update(existingOrder);
                                result = updatedOrder.WayBillNumber;
                            }
                        }

                        if (result != "")
                        {
                            scope.Complete();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(Json(result));
        }
        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 AddAddress([FromBody] dynamic addressData)
        {
            ValidateSession();
            var result = "";

            try
            {
                if (addressData != null)
                {
                    CustomerAddressMapping customerAddress = JsonConvert.DeserializeObject <CustomerAddressMapping>(JsonConvert.SerializeObject(addressData[0]));

                    //var jAddressObject = (JObject)addressData[0];
                    //var shippingAddressMappingId = Convert.ToString(jAddressObject.SelectToken("shippingAddressMappingId"));
                    //var billingAddressMappingId = Convert.ToString(jAddressObject.SelectToken("billingAddressMappingId"));

                    if (customerAddress != null)
                    {
                        _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 newAddressId = 0;

                        //using (var scope = new TransactionScope())
                        //{
                        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;

                            newAddressId = _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;

                            newAddressId = _addressLogic.Add(addressPoco).Id;
                        }

                        // This will ensure only one address is set as default address for the same type
                        if (customerAddress.IsDefault == true)
                        {
                            var 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 existingCustomerAddressMapping = customerAddressList.Where(c => c.AddressId == customerAddress.AddressId && c.AddressTypeId == customerAddress.AddressTypeId).FirstOrDefault();

                        if (existingCustomerAddressMapping != null)
                        {
                            existingCustomerAddressMapping.AddressId = newAddressId;
                            existingCustomerAddressMapping.IsDefault = customerAddress.IsDefault;
                            _customerAddressMappingLogic.Update(existingCustomerAddressMapping);
                        }
                        else
                        {
                            Lms_CustomerAddressMappingPoco customerAddressMappingPoco = new Lms_CustomerAddressMappingPoco();
                            customerAddressMappingPoco.CustomerId    = customerAddress.CustomerId;
                            customerAddressMappingPoco.AddressId     = customerAddress.AddressId;
                            customerAddressMappingPoco.AddressTypeId = customerAddress.AddressTypeId;
                            customerAddressMappingPoco.IsDefault     = customerAddress.IsDefault;
                            _customerAddressMappingLogic.Add(customerAddressMappingPoco);
                        }

                        //scope.Complete();

                        result = newAddressId.ToString();

                        //}
                    }
                }
            }
            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));
        }