Ejemplo n.º 1
0
        public ActionResult SaveCustomerAddress(CustomerAddressModel model)
        {
            var isValid = ModelState.IsValidField("FullName") && ModelState.IsValidField("Label") &&
                          ModelState.IsValidField("Address1") && ModelState.IsValidField("Locality") &&
                          ModelState.IsValidField("PostalCode") && ModelState.IsValidField("CountryCode");

            if (!isValid)
            {
                return(this.CurrentUmbracoPage());
            }
            ICustomerAddress customerAddress;

            if (!model.Key.Equals(Guid.Empty))
            {
                var existing = MerchelloServices.CustomerService.GetAddressByKey(model.Key);
                customerAddress = model.AsCustomerAddress(existing);
            }
            else
            {
                customerAddress = model.AsCustomerAddress();
            }

            MerchelloServices.CustomerService.Save(customerAddress);
            CustomerContext.Reinitialize(CurrentCustomer);
            return(this.SuccessfulRedirect(model.AccountPageId));
        }
Ejemplo n.º 2
0
        public void TestAddresses()
        {
            var os = new List <string>();

            os.Add("Line1,Line2,Line3,House name,House number,Flat/Apt,Address1,Address2");

            foreach (var tpl in testData)
            {
                var cam = new CustomerAddressModel {
                    Line1 = tpl.Item1,
                    Line2 = tpl.Item2,
                    Line3 = tpl.Item3,
                };

                cam.FillDetails();

                os.Add(string.Join(",", new [] {
                    cam.Line1,
                    cam.Line2,
                    cam.Line3,
                    cam.HouseName,
                    cam.HouseNumber,
                    cam.FlatOrApartmentNumber,
                    cam.Address1,
                    cam.Address2
                }));
            }             // for each

            Log.Msg("\n\n{0}\n\n", string.Join("\n", os));
        }         // TestAddresses
Ejemplo n.º 3
0
        public async Task <IActionResult> AddressCreate(CustomerAddressModel model, IFormCollection form)
        {
            var customer = await _customerService.GetCustomerById(model.CustomerId);

            if (customer == null)
            {
                //No customer found with the specified id
                return(RedirectToAction("List"));
            }

            //custom address attributes
            var customAttributes = await form.ParseCustomAddressAttributes(_addressAttributeParser, _addressAttributeService);

            var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarnings(customAttributes);

            foreach (var error in customAttributeWarnings)
            {
                ModelState.AddModelError("", error);
            }

            if (ModelState.IsValid)
            {
                var address = await _customerViewModelService.InsertAddressModel(customer, model, customAttributes);

                SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Addresses.Added"));
                return(RedirectToAction("AddressEdit", new { addressId = address.Id, customerId = model.CustomerId }));
            }

            //If we got this far, something failed, redisplay form
            await _customerViewModelService.PrepareAddressModel(model, null, customer, true);

            return(View(model));
        }
Ejemplo n.º 4
0
        public Error InsertOrUpdateCustomerAddress(CustomerAddressModel address, string lockGuid = "")
        {
            var error = ValidateAddressModel(address);

            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(CustomerAddress).ToString(), address.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "Street");
                }
                else
                {
                    CustomerAddress temp = null;
                    if (address.Id != 0)
                    {
                        temp = db.FindCustomerAddress(address.Id);
                    }
                    if (temp == null)
                    {
                        temp = new CustomerAddress();
                    }

                    MapToEntity(address, temp);

                    db.InsertOrUpdateCustomerAddress(temp);
                    address.Id = temp.Id;

                    db.Entry(temp).State = EntityState.Detached;
                }
            }
            return(error);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Prepare customer address model
        /// </summary>
        /// <param name="model">Customer address model</param>
        /// <param name="customer">Customer</param>
        /// <param name="address">Address</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Customer address model</returns>
        public virtual CustomerAddressModel PrepareCustomerAddressModel(CustomerAddressModel model,
                                                                        Customer customer, Address address, bool excludeProperties = false)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            if (address != null)
            {
                //fill in model values from the entity
                model = model ?? new CustomerAddressModel();

                //whether to fill in some of properties
                if (!excludeProperties)
                {
                    model.Address = address.ToModel(model.Address);
                }
            }

            model.CustomerId = customer.Id;

            //prepare address model
            PrepareAddressModel(model.Address, address);

            return(model);
        }
Ejemplo n.º 6
0
        public ActionResult UpdateAddress(string UpdateType, Models.Customer.CustomerAddress custAddress)
        {
            Models.Customer.CustomerAddressModel md = new CustomerAddressModel();
            Mapper.CreateMap <BusinessObjects.Province, Models.Customer.Province>();
            Mapper.CreateMap <BusinessObjects.City, Models.Customer.City>();
            Mapper.CreateMap <BusinessObjects.HomeOwnership, Models.Customer.HomeOwnership>();
            Mapper.CreateMap <BusinessObjects.AddressType, Models.Customer.AddressType>();
            IEnumerable <Models.Customer.Province>      Province      = Mapper.Map <IEnumerable <BusinessObjects.Province>, IEnumerable <Models.Customer.Province> >(service.getProvince());
            IEnumerable <Models.Customer.City>          City          = Mapper.Map <IEnumerable <BusinessObjects.City>, IEnumerable <Models.Customer.City> >(service.updateCity(custAddress.ProvinceID));
            IEnumerable <Models.Customer.HomeOwnership> HomeOwnership = Mapper.Map <IEnumerable <BusinessObjects.HomeOwnership>, IEnumerable <Models.Customer.HomeOwnership> >(service.getHomeOwnership());
            IEnumerable <Models.Customer.AddressType>   AddressType   = Mapper.Map <IEnumerable <BusinessObjects.AddressType>, IEnumerable <Models.Customer.AddressType> >(service.getAddressType(false));

            md.custAddress   = custAddress;
            md.Province      = Province;
            md.City          = City;
            md.HomeOwnership = HomeOwnership;
            md.AddressType   = AddressType;
            var pvr = new PartialViewResult();

            if (UpdateType == "update")
            {
                pvr = PartialView("_UpdateAddress", md);
            }
            else if (UpdateType == "add")
            {
                pvr = PartialView("_AddAddress", md);
            }
            return(pvr);
        }
Ejemplo n.º 7
0
        public ActionResult Register(CustomerAddressModel cus)
        {
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors })
                         .ToArray();

            if (ModelState.IsValid)
            {
                //CustomerModel cusModel = new CustomerModel();
                //AddressModel addModel = new AddressModel();

                string password        = Cipher.Encrypt(cus.password);
                string confirmPassword = Cipher.Encrypt(cus.confirmPassword);


                CustomerModel customerModel = new CustomerModel();
                customerModel.firstName       = cus.firstName;
                customerModel.lastName        = cus.lastName;
                customerModel.phone           = cus.phone;
                customerModel.email           = cus.email;
                customerModel.password        = password;
                customerModel.confirmPassword = confirmPassword;
                customerModel.state           = "Active";

                AddressModel addressModel = new AddressModel();
                addressModel.address    = cus.address;
                addressModel.city       = cus.city;
                addressModel.postalCode = cus.postalCode;

                Context.CustomerModelSet.Add(customerModel);
                Context.AddressModelSet.Add(addressModel);
                Context.SaveChanges();


                MailMessage message = new MailMessage();
                message.From = new System.Net.Mail.MailAddress("*****@*****.**");
                message.To.Add(new System.Net.Mail.MailAddress(cus.email));
                message.Subject    = "WELCOME TO BUYALOT!!";
                message.Body       = string.Format("Welcome {0} ,<br /><br />Enjoy your Shopping :) <br />Your password is: {1} .<br /><br />Thank You. <br /> Regards, <br /> Buyalot DevTeam", cus.firstName, cus.password);
                message.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host      = "smtp.gmail.com";
                smtp.EnableSsl = true;
                NetworkCredential NetworkCred = new NetworkCredential();
                smtp.UseDefaultCredentials = true;
                smtp.Credentials           = NetworkCred;
                smtp.Port = 587;

                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.Send(message);

                return(RedirectToAction("Login", "Account"));
            }

            return(View(cus));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Maps a CustomerAddressModel view model to a CustomerAddress data model
 /// </summary>
 /// <param name="address"></param>
 /// <returns></returns>
 public static CustomerAddress MapCustomerAddress(CustomerAddressModel address)
 {
     return(new CustomerAddress {
         AddressLine1 = address.AddressLine1,
         AddressLine2 = address.AddressLine2,
         City = address.City,
         State = address.State,
         PostalCode = address.PostalCode,
         Country = address.Country,
         CreatedOn = DateTime.UtcNow,
         UpdatedOn = DateTime.UtcNow,
     });
 }
Ejemplo n.º 9
0
        private CustomerAddressModel GetCustomerAddress(Customer customer)
        {
            var model = new CustomerAddressModel();

            model.userName     = customer.GetCustomerAttributeValue <string>(CustomerAttributeNames.UserName);
            model.telNumber    = customer.GetCustomerAttributeValue <string>(CustomerAttributeNames.TelNumber);
            model.provinceName = customer.GetCustomerAttributeValue <string>(CustomerAttributeNames.ProvinceName);
            model.cityName     = customer.GetCustomerAttributeValue <string>(CustomerAttributeNames.CityName);
            model.countryName  = customer.GetCustomerAttributeValue <string>(CustomerAttributeNames.CountryName);
            model.detailInfo   = customer.GetCustomerAttributeValue <string>(CustomerAttributeNames.DetailInfo);
            model.Id           = customer.Id;
            return(model);
        }
Ejemplo n.º 10
0
        }         // HouseNumber

        public void SetAddress(string postCode, string line1, string line2, string line3)
        {
            Postcode = postCode;

            var cam = new CustomerAddressModel {
                Line1 = line1,
                Line2 = line2,
                Line3 = line3,
            };

            cam.FillDetails();

            HouseNumber = string.IsNullOrWhiteSpace(cam.HouseName) ? cam.HouseNumber : cam.HouseName;
        }         // SetAddress
Ejemplo n.º 11
0
 //Map a CustomerAddressModel view model into a CustomerAddress data model
 public static CustomerAddress MapCustomerAddress(CustomerAddressModel address)
 {
     return(new CustomerAddress {
         Id = address.Id,
         AddressLine1 = address.AddressLine1,
         AddressLine2 = address.AddressLine2,
         City = address.City,
         State = address.State,
         Country = address.Country,
         PostalCode = address.PostalCode,
         CreatedOn = address.CreatedOn,
         UpdatedOn = address.UpdatedOn
     });
 }
Ejemplo n.º 12
0
        public async Task <IActionResult> AddressCreate(string customerId)
        {
            var customer = await _customerService.GetCustomerById(customerId);

            if (customer == null)
            {
                //No customer found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new CustomerAddressModel();
            await _customerViewModelService.PrepareAddressModel(model, null, customer, false);

            return(View(model));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Maps a CustomerAddress data model to a CustomerAddressModel view model
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        ///


        public static CustomerAddressModel MapCustomerAddress(CustomerAddress address)
        {
            var Address = new CustomerAddressModel
            {
                AddressLine1 = address.AddressLine1,
                AddressLine2 = address.AddressLine2,
                City         = address.City,
                State        = address.State,
                Country      = address.Country,
                PostalCode   = address.PostalCode,
                CreatedOn    = DateTime.UtcNow,
                UpdatedOn    = DateTime.UtcNow
            };

            return(Address);
        }
Ejemplo n.º 14
0
        public static CustomerAddress MapCustomerAddress(CustomerAddressModel address)
        {
            var now = DateTime.UtcNow;

            return(new CustomerAddress
            {
                AddressLine1 = address.AddressLine1,
                AddressLine2 = address.AddressLine2,
                City = address.City,
                Province = address.Province,
                Country = address.Country,
                PostalCode = address.PostalCode,
                CreatedOn = now,
                UpdatedOn = now
            });
        }
Ejemplo n.º 15
0
        public async Task <ActionResult <CustomerAddressModel> > GetCustomerAddress(string email, string name, string surname, string phoneNumber)
        {
            var _customerAddressModel = new CustomerAddressModel();
            var addressList           = new List <CustomerAddressData>();

            var customerData = await _context.Customer.Where(p => p.Email == email ||
                                                             p.Name == name &&
                                                             p.Surname == surname &&
                                                             p.PhoneNumber == phoneNumber)
                               .Select(p => new CustomerData
            {
                CustomerID  = p.CustomerId,
                Name        = p.Name,
                Surname     = p.Surname,
                Email       = p.Email,
                PhoneNumber = p.PhoneNumber
            })
                               .FirstAsync();

            var customerAddress = await _context.CustomerCustomerAddress.Where(p => p.Customer == customerData.CustomerID)
                                  .Select(p => p.CustomerAddress)
                                  .ToListAsync();

            foreach (var address in customerAddress)
            {
                var addressTemp = await _context.CustomerAddress.Where(p => p.CustomerAddressId == address)
                                  .Select(p => new CustomerAddressData
                {
                    CustomerAddressId = p.CustomerAddressId,
                    Province          = p.Province,
                    Zipcode           = p.Zipcode,
                    City            = p.City,
                    Street          = p.Street,
                    BuildingNumber  = p.BuildingNumber,
                    ApartmentNumber = p.ApartmentNumber,
                })
                                  .FirstAsync();

                addressList.Add(addressTemp);
            }

            _customerAddressModel.CustomerData        = customerData;
            _customerAddressModel.CustomerAddressData = addressList;

            return(_customerAddressModel);
        }
Ejemplo n.º 16
0
        public Error ValidateAddressModel(CustomerAddressModel model)
        {
            var error = isValidRequiredString(getFieldValue(model.Street), 255, "Street", EvolutionResources.errStreetRequired);

            if (!error.IsError)
            {
                error = isValidRequiredString(getFieldValue(model.City), 50, "City", EvolutionResources.errCityRequired);
            }
            if (!error.IsError)
            {
                error = isValidRequiredString(getFieldValue(model.State), 20, "State", EvolutionResources.errStateRequired);
            }
            if (!error.IsError)
            {
                error = isValidRequiredString(getFieldValue(model.Postcode), 10, "Postcode", EvolutionResources.errPostCodeRequired);
            }

            return(error);
        }
        public ActionResult SaveCustomerAddress(CustomerAddressModel model)
        {
            var isValid = ModelState.IsValidField("FullName") && ModelState.IsValidField("Label") &&
                          ModelState.IsValidField("Address1") && ModelState.IsValidField("Locality") &&
                          ModelState.IsValidField("PostalCode") && ModelState.IsValidField("CountryCode") &&
                          !model.CustomerKey.Equals(Guid.Empty);

            var customer = MerchelloServices.CustomerService.GetByKey(model.CustomerKey);

            if (customer == null)
            {
                throw new NullReferenceException("customer was null");
            }

            if (!isValid)
            {
                return(this.CurrentUmbracoPage());
            }
            ICustomerAddress customerAddress;

            if (!model.Key.Equals(Guid.Empty))
            {
                var existing = MerchelloServices.CustomerService.GetAddressByKey(model.Key);
                customerAddress = model.AsCustomerAddress(existing);
            }
            else
            {
                customerAddress = model.AsCustomerAddress();
            }

            // Using the extension internally adds or updates against the existing addresses
            // and then saves the customer record rather than the address independently.
            // This asserts the customer index (Examine) will be updated correctly.
            //// http://issues.merchello.com/youtrack/issue/M-786
            customer.SaveCustomerAddress(customerAddress);

            // This method is obsolete and never should have been exposed as it "may not" reindex
            // the customer correctly in Examine.
            // MerchelloServices.CustomerService.Save(customerAddress);
            CustomerContext.Reinitialize(CurrentCustomer);
            return(this.SuccessfulRedirect(model.AccountPageId));
        }
Ejemplo n.º 18
0
        public CustomerAddressModel FindCustomerAddressModel(int id, CompanyModel company, int customerId, bool bCreateEmptyIfNotfound = true)
        {
            CustomerAddressModel model = null;

            var a = db.FindCustomerAddress(id);

            if (a == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new CustomerAddressModel {
                        CompanyId = company.Id, CustomerId = customerId
                    };

                    // Default the country according to the company default location
                    if (company.DefaultLocationID != null)
                    {
                        var location = db.FindLocation(company.DefaultLocationID.Value);
                        if (location != null)
                        {
                            string countryName = location.Country;
                            if (countryName.ToLower() == "england")
                            {
                                countryName = "United Kingdom";                                     // Handles existing data
                            }
                            var country = db.FindCountry(countryName);
                            if (country != null)
                            {
                                model.CountryId = country.Id;
                            }
                        }
                    }
                }
            }
            else
            {
                model = MapToModel(a);
            }

            return(model);
        }
        public ActionResult SaveCustomerAddress(CustomerAddressModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.CurrentUmbracoPage());
            }
            ICustomerAddress customerAddress;

            if (!model.Key.Equals(Guid.Empty))
            {
                var existing = MerchelloServices.CustomerService.GetAddressByKey(model.Key);
                customerAddress = model.AsCustomerAddress(existing);
            }
            else
            {
                customerAddress = model.AsCustomerAddress();
            }

            MerchelloServices.CustomerService.Save(customerAddress);
            CustomerContext.Reinitialize(CurrentCustomer);
            return(this.SuccessfulRedirect(model.AccountPageId));
        }
        public IActionResult AddressEdit(CustomerAddressModel model, IFormCollection form)
        {
            var customer = _customerService.GetCustomerById(model.CustomerId);

            if (customer == null)
            {
                //No customer found with the specified id
                return(RedirectToAction("List"));
            }

            var address = customer.Addresses.Where(x => x.Id == model.Address.Id).FirstOrDefault();

            if (address == null)
            {
                //No address found with the specified id
                return(RedirectToAction("Edit", new { id = customer.Id }));
            }

            //custom address attributes
            var customAttributes        = form.ParseCustomAddressAttributes(_addressAttributeParser, _addressAttributeService);
            var customAttributeWarnings = _addressAttributeParser.GetAttributeWarnings(customAttributes);

            foreach (var error in customAttributeWarnings)
            {
                ModelState.AddModelError("", error);
            }

            if (ModelState.IsValid)
            {
                address = _customerViewModelService.UpdateAddressModel(customer, address, model, customAttributes);
                SuccessNotification(_localizationService.GetResource("Admin.Customers.Customers.Addresses.Updated"));
                return(RedirectToAction("AddressEdit", new { addressId = model.Address.Id, customerId = model.CustomerId }));
            }
            //If we got this far, something failed, redisplay form
            _customerViewModelService.PrepareAddressModel(model, address, customer, true);

            return(View(model));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> AddressEdit(string addressId, string customerId)
        {
            var customer = await _customerService.GetCustomerById(customerId);

            if (customer == null)
            {
                //No customer found with the specified id
                return(RedirectToAction("List"));
            }

            var address = customer.Addresses.Where(x => x.Id == addressId).FirstOrDefault();

            if (address == null)
            {
                //No address found with the specified id
                return(RedirectToAction("Edit", new { id = customer.Id }));
            }

            var model = new CustomerAddressModel();
            await _customerViewModelService.PrepareAddressModel(model, address, customer, false);

            return(View(model));
        }
Ejemplo n.º 22
0
        CustomerAddressModel createCustomerAddress(int companyId, int customerId, UserModel user, AddressType addressType)
        {
            var lov       = db.FindLOV(LOVName.AddressType);
            var addrsType = lov.LOVItems
                            .Where(lovi => lovi.ItemValue1.ToString() == ((int)addressType).ToString())
                            .FirstOrDefault();

            if (countryList == null)
            {
                countryList = LookupService.FindCountriesListModel();
            }
            var rnd = RandomInt(0, countryList.Items.Count() - 1);

            CustomerAddressModel model = new CustomerAddressModel {
                CompanyId       = companyId,
                CustomerId      = customerId,
                AddressTypeId   = addrsType.Id,
                AddressType     = (AddressType)Convert.ToInt32(addrsType.ItemValue1),
                AddressTypeText = addrsType.ItemText,
                Street          = RandomString(),
                City            = RandomString(),
                State           = RandomString().Left(20),
                CountryId       = countryList.Items[rnd].Id,
                CountryName     = countryList.Items[rnd].CountryName,
                Postcode        = RandomString().Left(10),
                DateStart       = DateTimeOffset.Now,
                DateEnd         = DateTimeOffset.Now.AddDays(1)
            };
            var error = CustomerService.InsertOrUpdateCustomerAddress(model, "");

            Assert.IsFalse(error.IsError, error.Message);

            countryList.Items.RemoveAt(rnd);    // So we don't use the same country again

            return(model);
        }
Ejemplo n.º 23
0
 public string LockCustomerAddress(CustomerAddressModel model)
 {
     return(db.LockRecord(typeof(CustomerAddress).ToString(), model.Id));
 }
    public IHttpActionResult UpdateCustomerAddress([FromBody]  CustomerAddressModel theCustomer)
    {
        //Instantiate the object
        designEntity = new online_tshirt_designingEntities();

        int updatedRecord = 0;


        //Execute the query and return the entity object
        customer_address customerMatches = designEntity.customer_address.FirstOrDefault((c) => c.CustAddrId == theCustomer.CustAddrId && c.CustId == theCustomer.CustId);

        if (customerMatches == null)
        {
            //Generates random numbers for CustAddrId column
            DateTime dTime = DateTime.Now;


            //Sets Unique id to CustId & CustAddrId column
            string id = Convert.ToString(dTime.Millisecond);

            //Creates the new customer address model
            customer_address newCustomerAddress = new customer_address
            {
                CustAddrId = id,

                CustShipAddr = theCustomer.CustShipAddr,

                CustShipCountry = theCustomer.CustShipCountry,

                CustShipState = theCustomer.CustShipState,

                CustShipCity = theCustomer.CustShipCity,

                CustShipPinCode = theCustomer.CustShipPinCode,

                CustId = theCustomer.CustId
            };

            try
            {
                //Finally commit the changes the changes and insert the record
                //In the database
                designEntity.customer_address.Add(newCustomerAddress);

                updatedRecord = designEntity.SaveChanges();
            }
            catch (Exception error)
            {
                System.Diagnostics.Debug.WriteLine("Error in Linq", error);
            }
        }

        //Changes the entity object, if it matches
        else
        {
            customerMatches.CustShipAddr = theCustomer.CustShipAddr;

            customerMatches.CustShipCountry = theCustomer.CustShipCountry;

            customerMatches.CustShipState = theCustomer.CustShipState;

            customerMatches.CustShipCity = theCustomer.CustShipCity;

            customerMatches.CustShipPinCode = theCustomer.CustShipPinCode;


            try
            {
                //Finally commit the changes the changes and insert the record
                //In the database

                updatedRecord = designEntity.SaveChanges();
            }
            catch (Exception error)
            {
                System.Diagnostics.Debug.WriteLine("Error in Linq", error);
            }
        }

        //IF records get updated successfully
        if (updatedRecord > 0)
        {
            //Return this customerEntireData
            var customerEntireData = from cust in designEntity.customers
                                     join custAddr in designEntity.customer_address
                                     on cust.CustId equals custAddr.CustId
                                     where cust.CustId == theCustomer.CustId
                                     select new
            {
                cust.CustId,
                cust.CustFirstName,
                cust.CustLastName,
                cust.CustMobNo,
                cust.CustEmailAddr,
                cust.CustImg,

                custAddr.CustAddrId,
                custAddr.CustShipAddr,
                custAddr.CustShipCountry,
                custAddr.CustShipCity,
                custAddr.CustShipState,
                custAddr.CustShipPinCode
            };
            return(Ok(customerEntireData));
        }
        return(NotFound());
    }
        public Error CreateOrderConfirmationPdf(SalesOrderHeaderModel soh, DocumentTemplateModel template,
                                                string pdfFile,
                                                bool showCancelledItems,
                                                ref string outputFile,
                                                int maxItems = Int32.MaxValue)
        {
            var error = new Error();

            string tempFile = MediaService.MediaService.GetTempFile(".html");

            if (string.IsNullOrEmpty(pdfFile))
            {
                outputFile = MediaService.MediaService.GetTempFile().FolderName() + "\\" + soh.OrderNumber + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
            }
            else
            {
                outputFile = pdfFile;
            }

            // Insert the lines
            decimal subTotal       = 0,
                    subTotalIncGst = 0,
                    freightTotal   = 0;

            CompanyService.CompanyService companyService = new CompanyService.CompanyService(db);
            var company = companyService.FindCompanyModel(soh.CompanyId);

            CustomerService.CustomerService customerService = new CustomerService.CustomerService(db);
            var customer = customerService.FindCustomerModel(soh.CustomerId == null ? 0 : soh.CustomerId.Value,
                                                             company);

            var paymentTerms = LookupService.FindPaymentTermModel(soh.TermsId == null ? 0 : soh.TermsId.Value);

            var taxCode = LookupService.FindTaxCodeModel(customer.TaxCodeId);

            subTotalIncGst = subTotal + (taxCode.TaxPercentageRate == null ? 0 : (subTotal / 100 * taxCode.TaxPercentageRate.Value));

            var currency = LookupService.FindCurrencyModel(company.DefaultCurrencyID == null ? 0 : company.DefaultCurrencyID.Value);

            Dictionary <string, string>         headerProps = new Dictionary <string, string>();
            List <Dictionary <string, string> > records     = new List <Dictionary <string, string> >();

            AddCompanyInformation(company, headerProps);

            headerProps.AddProperty("ORDERNUMBER", soh.OrderNumber.ToString());
            headerProps.AddProperty("CUSTPO", soh.CustPO);
            headerProps.AddProperty("ORDERDATE", formatDate(soh.OrderDate, company.DateFormat));
            headerProps.AddProperty("PAYMENTTERMS", paymentTerms.TermText);

            var salesMgr = customerService.FindBrandCategorySalesPersonsModel(company, customer, soh.BrandCategoryId.Value, SalesPersonType.AccountAdmin).FirstOrDefault();

            if (salesMgr != null)
            {
                headerProps.AddProperty("ACCOUNTMANAGER", salesMgr.UserName);
            }
            else
            {
                headerProps.AddProperty("ACCOUNTMANAGER", "");
            }

            headerProps.AddProperty("CUSTOMERNAME", customer.Name);

            var contact = customerService.FindPrimaryCustomerContactsModel(customer)
                          .FirstOrDefault();

            headerProps.AddProperty("CUSTOMERCONTACT", contact.ContactFirstname + " " + contact.ContactSurname);

            var addrs = customerService.FindCurrentCustomerAddresses(customer, AddressType.Billing)
                        .FirstOrDefault();

            if (addrs == null)
            {
                addrs = new CustomerAddressModel();
            }

            headerProps.AddProperty("STREET", addrs.Street);
            headerProps.AddProperty("CITY", addrs.City);
            headerProps.AddProperty("STATE", addrs.State);
            headerProps.AddProperty("POSTCODE", addrs.Postcode);
            headerProps.AddProperty("COUNTRY", addrs.CountryName);
            headerProps.AddProperty("PHONENO", contact.ContactPhone1);
            headerProps.AddProperty("FAXNUMBER", contact.ContactFax);

            headerProps.AddProperty("DELIVERYADDRESS", soh.FullAddress.Replace("\r\n", "<br/>"));

            headerProps.AddProperty("TAXNAME", taxCode.TaxCode);
            headerProps.AddProperty("CURRENCYSYMBOL", currency.CurrencySymbol);

            var shipMethod = LookupService.FindLOVItemModel((soh.ShippingMethodId == null ? 0 : soh.ShippingMethodId.Value),
                                                            LOVName.ShippingMethod);

            headerProps.AddProperty("DELIVERYVIA", shipMethod.ItemText);

            string deliveryWindow = "";

            if (soh.DeliveryWindowOpen != null)
            {
                deliveryWindow = soh.DeliveryWindowOpen.Value.ToString(company.DateFormat);
            }
            if (soh.DeliveryWindowClose != null)
            {
                if (!string.IsNullOrEmpty(deliveryWindow))
                {
                    deliveryWindow += " - ";
                }
                deliveryWindow += soh.DeliveryWindowClose.Value.ToString(company.DateFormat);
            }
            headerProps.AddProperty("DELIVERYWINDOW", deliveryWindow);
            headerProps.AddProperty("SALESPERSON", soh.SalesPersonName);

            // Add items
            int itemCount = 1;

            foreach (var sod in FindSalesOrderDetailListModel(company, soh))
            {
                if (sod.LineStatusId != (int)SalesOrderLineStatus.Cancelled || showCancelledItems)
                {
                    decimal unitPriceExTax = (sod.UnitPriceExTax == null ? 0 : sod.UnitPriceExTax.Value);
                    decimal discountPc     = (sod.DiscountPercent == null ? 0 : sod.DiscountPercent.Value);
                    decimal linePrice      = (sod.OrderQty.Value * unitPriceExTax - ((sod.OrderQty.Value * unitPriceExTax) / 100 * discountPc));

                    Dictionary <string, string> line = new Dictionary <string, string>();
                    line.AddProperty("ORDERQTY", sod.OrderQty);

                    var product = ProductService.FindProductModel(sod.ProductId == null ? 0 : sod.ProductId.Value,
                                                                  null, company);
                    line.AddProperty("ITEMNUMBER", product.ItemNumber);
                    line.AddProperty("DESCRIPTION", itemCount.ToString() + " " + sod.ProductDescription);

                    var ecd = AllocationService.CalculateExpectedCompletionDate(sod);
                    if (ecd != null)
                    {
                        line.AddProperty("INSTOCK", ecd.Value.ToString(company.DateFormat));
                    }
                    else
                    {
                        line.AddProperty("INSTOCK", "");
                    }

                    line.AddProperty("UNITPRICEEXTAX", unitPriceExTax.ToString("#,##0.000"));
                    line.AddProperty("DISCOUNTPERCENT", discountPc.ToString("#,##0.00"));
                    line.AddProperty("LINEPRICE", linePrice.ToString("#,##0.000"));

                    subTotal += linePrice;

                    records.Add(line);
                    itemCount++;
                }
            }

            headerProps.AddProperty("TAXNAME", taxCode.TaxCode);
            headerProps.AddProperty("CURRENCYSYMBOL", currency.CurrencySymbol);

            headerProps.AddProperty("SALEAMOUNTEX", subTotal.ToString("#,##0.00"));

            freightTotal = CalculateEstimatedFreight(soh, customer);
            headerProps.AddProperty("ESTIMATEDFREIGHT", freightTotal.ToString("#,##0.00"));

            subTotal += freightTotal;

            subTotalIncGst = subTotal + (taxCode.TaxPercentageRate == null ? 0 : (subTotal / 100 * taxCode.TaxPercentageRate.Value));
            headerProps.AddProperty("SALEAMOUNTINC", subTotalIncGst.ToString("#,##0.00"));

            headerProps.AddProperty("GST", (subTotalIncGst - subTotal).ToString("#,##0.00"));

            return(DocumentService.CreateDocumentPdf(headerProps, records, template.QualTemplateFile, outputFile, maxItems));
        }
Ejemplo n.º 26
0
 public void MapToEntity(CustomerAddressModel model, CustomerAddress entity)
 {
     Mapper.Map <CustomerAddressModel, CustomerAddress>(model, entity);
 }
Ejemplo n.º 27
0
        public virtual async Task <CustomerAddressModel> PrepareCompanyCustomerAddressModelAsync(CustomerAddressModel model,
                                                                                                 Company company, Address address, bool excludeProperties = false)
        {
            if (company == null)
            {
                throw new ArgumentNullException(nameof(company));
            }

            if (address != null)
            {
                //fill in model values from the entity
                model ??= new CustomerAddressModel();

                //whether to fill in some of properties
                if (!excludeProperties)
                {
                    model.Address = address.ToModel(model.Address);
                }
            }

            model.CustomerId = company.Id;

            //prepare address model
            await _addressModelFactory.PrepareAddressModelAsync(model.Address, address);

            model.Address.FirstNameRequired      = true;
            model.Address.LastNameRequired       = true;
            model.Address.EmailRequired          = true;
            model.Address.CompanyRequired        = _addressSettings.CompanyRequired;
            model.Address.CityRequired           = _addressSettings.CityRequired;
            model.Address.CountyRequired         = _addressSettings.CountyRequired;
            model.Address.StreetAddressRequired  = _addressSettings.StreetAddressRequired;
            model.Address.StreetAddress2Required = _addressSettings.StreetAddress2Required;
            model.Address.ZipPostalCodeRequired  = _addressSettings.ZipPostalCodeRequired;
            model.Address.PhoneRequired          = _addressSettings.PhoneRequired;
            model.Address.FaxRequired            = _addressSettings.FaxRequired;

            return(model);
        }
Ejemplo n.º 28
0
        public IActionResult update_customer(string cus_id, string add_id, string ct_id, string credit_id, string sale_id, string ts_id, string cus_type, string cus_prefix, string cus_name, string cus_lastname, string cus_name_contact, string cus_trade, string cus_tax, string add_num, string add_alley, string add_road, string add_province, string add_amphur, string add_distict, string add_postcode, string add_type_status, string add_branch, string ct_tel, string ct_fax, string ct_email, string ct_web, string credit_money, string credit_condition, string line_sale, string name_sale, string at_customer_name, string at_num, string at_alley, string at_road, string at_province, string at_amphur, string at_district, string at_postcode)
        {
            customerTypeModel c_tp = new customerTypeModel();

            c_tp.type_id = cus_type;
            c_tp.select_cus_type();


            CustomerModel cus = new CustomerModel();

            cus.cus_id            = cus_id;
            cus.cus_ref_type_id   = c_tp.type_code;
            cus.cus_ref_prefix_id = cus_prefix;
            cus.cus_name          = cus_name;
            cus.cus_name_contact  = cus_name_contact;
            cus.cus_trade         = cus_trade;
            cus.cus_tax           = cus_tax;
            cus.update_customer();

            CustomerAddressModel add = new CustomerAddressModel();

            add.add_id          = add_id;
            add.add_num         = add_num;
            add.add_alley       = add_alley;
            add.add_road        = add_road;
            add.add_province    = add_province;
            add.add_amphur      = add_amphur;
            add.add_district    = add_distict;
            add.add_poscode     = add_postcode;
            add.add_type_status = add_type_status;
            add.add_branch      = add_branch;
            add.add_ref_cus_id  = cus_id;
            add.update_address();

            CustomerContactModel ct = new CustomerContactModel();

            ct.ct_id         = ct_id;
            ct.ct_tel        = ct_tel;
            ct.ct_fax        = ct_fax;
            ct.ct_email      = ct_email;
            ct.ct_web        = ct_web;
            ct.ct_ref_cus_id = cus_id;
            ct.update_contact();

            CustomerCreditModel cd = new CustomerCreditModel();

            cd.credit_id            = credit_id;
            cd.credit_money         = credit_money;
            cd.credit_ref_condition = credit_condition;
            cd.credit_ref_cus_id    = cus_id;
            cd.update_credit();

            CustomerLineSaleModel ls = new CustomerLineSaleModel();

            ls.cs_id          = sale_id;
            ls.cs_ref_line_id = line_sale;
            ls.cs_sale_name   = name_sale;
            ls.cs_ref_cus_id  = cus_id;
            ls.update_cus_line();

            CustomerTransportModel tp = new CustomerTransportModel();

            tp.at_id            = ts_id;
            tp.at_customer_name = at_customer_name;
            tp.at_num           = at_num;
            tp.at_alley         = at_alley;
            tp.at_road          = at_road;
            tp.at_province      = at_province;
            tp.at_amphur        = at_amphur;
            tp.at_district      = at_district;
            tp.at_postcode      = at_postcode;
            tp.at_ref_cus_id    = cus_id;
            tp.update_cus_tran();



            return(RedirectToAction("customer", "Customer", new { add = add.add_id }));
        }
Ejemplo n.º 29
0
        public IActionResult editcustomer(string cus)
        {
            ViewData["cus_id"] = cus;

            CustomerModel ctm = new CustomerModel();

            ctm.select_customer(" cus_id = '" + cus + "'");
            ViewData["cus_code"]         = ctm.cus_code;
            ViewData["cus_name"]         = ctm.cus_name;
            ViewData["cus_name_contact"] = ctm.cus_name_contact;
            ViewData["cus_trade"]        = ctm.cus_trade;
            ViewData["cus_tax"]          = ctm.cus_tax;

            customerTypeModel ct = new customerTypeModel();

            ViewData["cus_type"] = ct.drop_cus_type_code(ctm.cus_ref_type_id);

            prefixModel px = new prefixModel();

            ViewData["prefix"] = px.drop_prefix(ctm.cus_ref_prefix_id);
            px.select_prefix("prefix_id = '" + ctm.cus_ref_prefix_id + "'");
            ViewData["last_name"] = px.prefix_ending;


            CustomerAddressModel ca = new CustomerAddressModel();

            ca.select_address("add_ref_cus_id = '" + cus + "'");
            ViewData["add_num"]      = ca.add_num;
            ViewData["add_alley"]    = ca.add_alley;
            ViewData["add_road"]     = ca.add_road;
            ViewData["add_postcode"] = ca.add_poscode;
            ViewData["add_status"]   = ca.add_type_status;
            ViewData["add_branch"]   = ca.add_branch;
            ViewData["add_id"]       = ca.add_id;

            provinceModel pv = new provinceModel();
            ampuresModel  am = new ampuresModel();
            districts     dt = new districts();

            ViewData["province"] = pv.drop_province(ca.add_province);
            ViewData["amphur"]   = am.dorp_amphur(ca.add_amphur);
            ViewData["district"] = dt.drop_district(ca.add_district);


            CustomerContactModel c_t = new CustomerContactModel();

            c_t.select_contact("ct_ref_cus_id = '" + cus + "'");
            ViewData["ct_tel"]   = c_t.ct_tel;
            ViewData["ct_fax"]   = c_t.ct_fax;
            ViewData["ct_email"] = c_t.ct_email;
            ViewData["ct_web"]   = c_t.ct_web;
            ViewData["ct_id"]    = c_t.ct_id;


            CustomerCreditModel crd = new CustomerCreditModel();

            crd.select_credit("credit_ref_cus_id = '" + cus + "'");
            ViewData["credit_money"] = crd.credit_money;
            ViewData["credit_id"]    = crd.credit_id;

            conditionPayModel cd = new conditionPayModel();

            ViewData["condition"] = cd.drop_con_pay(crd.credit_ref_condition);


            CustomerLineSaleModel cl = new CustomerLineSaleModel();

            cl.select_cus_line("cs_ref_cus_id = '" + cus + "'");
            ViewData["sale_name"] = cl.cs_sale_name;
            ViewData["sale_id"]   = cl.cs_id;

            lineModel ln = new lineModel();

            ViewData["line"] = ln.drop_line(cl.cs_ref_line_id);

            line_saleModel ls = new line_saleModel();

            ViewData["line_sale"] = ls.drop_line_sale("");


            CustomerTransportModel ts = new CustomerTransportModel();

            ts.select_cus_tran("at_ref_cus_id = '" + cus + "'");
            ViewData["name_ts"]     = ts.at_customer_name;
            ViewData["num_ts"]      = ts.at_num;
            ViewData["alley_ts"]    = ts.at_alley;
            ViewData["road_ts"]     = ts.at_road;
            ViewData["postcode_ts"] = ts.at_postcode;

            ViewData["province_ts"] = pv.drop_province(ts.at_province);
            ViewData["amphur_ts"]   = am.dorp_amphur(ts.at_amphur);
            ViewData["district_ts"] = dt.drop_district(ts.at_district);
            ViewData["ts_id"]       = ts.at_id;


            return(View());
        }
Ejemplo n.º 30
0
 public ActionResult RenderCustomerAddressForm(CustomerAddressModel model)
 {
     return(this.PartialView(PathHelper.GetThemePartialViewPath(model.Theme, "CustomerAddressForm"), model));
 }