public ActionResult Create(CompanyViewModel model)
        {
            if (ModelState.IsValid)
            {
                var company = new BOCompany();
                Mapper.Map<CompanyViewModel, BOCompany>(model, company);
                Mapper.Map<CompanyViewModel, BOAddress>(model, company.ShippingAddress);

                if (_companyService.CompanyNameExists(company))
                {
                    List<KeyValuePair<long, string>> statesdata = _stateProvinceService.GetAll();
                    model.StateList = new SelectList(statesdata, SelectLists.DataValueField, SelectLists.DataTextField, model.State);
                    model.Message = "A Company already exists with this name";
                    return View(model);
                }

                _companyService.Save(company);

                return RedirectToAction("Index");
            }

            List<KeyValuePair<long, string>> states = _stateProvinceService.GetAll();
            model.StateList = new SelectList(states, SelectLists.DataValueField, SelectLists.DataTextField, model.State);

            return View(model);
        }
        public void Save(BOCompany company)
        {
            string message = string.Empty;

            var addressRepository = _repositoryFactory.GetRepository<BOAddress, BOAddressCollection>();
            var companyAddressXRepository = _repositoryFactory.GetRepository<BOCompanyAddressX, BOCompanyAddressXCollection>();

            addressRepository.Save(company.ShippingAddress);
            _companyRepository.Save(company);

            BOCompanyAddressX companyAddressX = null;
            if (company.CompanyAddressXs != null && company.CompanyAddressXs.Count > 0)
            {
                companyAddressX = (BOCompanyAddressX)company.CompanyAddressXs[0];
            }
            else
            {
                companyAddressX = new BOCompanyAddressX();
            }

            companyAddressX.Company = company;
            companyAddressX.Address = company.ShippingAddress;

            companyAddressXRepository.Save(companyAddressX);
        }
 public bool CompanyNameExists(BOCompany company)
 {
     if (_companyRepository.GetAll().Any(c => c.Name.ToLower() == company.Name.Trim().ToLower()))
     {
         return true;
     }
     return false;
 }
 public BOCompanyComparer(BOCompany.Columns column, BOCompany.SortDirections direction)
 {
     _column = column;
     _direction = direction;
 }