public ActionResult Create(CompanyProfileEditModel viewModel)
        {
            if (ModelState.IsValid)
            {
                CompanyProfile toAdd = new CompanyProfile
                {
                    Address1 = viewModel.Address1,
                    Address2 = viewModel.Address2,
                    BusinessType = viewModel.BusinessType.Value,
                    City = viewModel.City,
                    CompanyName = viewModel.CompanyName,
                    OperatingDistance = viewModel.OperatingDistance,
                    Phone = Util.ConvertPhoneForStorage(viewModel.Phone),
                    PostalCode = viewModel.PostalCode,
                    Published = viewModel.Published,
                    StateId = viewModel.StateId,
                    Website = viewModel.Website,
                    SubscriptionStatus = viewModel.Subscribed ? SubscriptionStatus.Paid : SubscriptionStatus.Free
                };

                if (_service.Create(toAdd))
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    Util.MapValidationErrors(_service.ValidationDic, this.ModelState);
                }
            }

            rePopViewModel(viewModel);
            return View(viewModel);
        }
        //
        // GET: /Admin/Company/Create
        public ActionResult Create()
        {
            CompanyProfileEditModel viewModel = new CompanyProfileEditModel();
            viewModel.States = _service.GetStates().Select(s => new SelectListItem { Text = s.Abbr, Value = s.Id.ToString() });
            viewModel.BusinessTypes = Util.CreateSelectListFromEnum(typeof(BusinessType));

            return View(viewModel);
        }
        public ActionResult Edit(CompanyProfileEditModel viewModel)
        {
            if (ModelState.IsValid)
            {
                CompanyProfile toUpdate = _service.Get(viewModel.Id);

                toUpdate.Address1 = viewModel.Address1;
                toUpdate.Address2 = viewModel.Address2;
                toUpdate.BusinessType = viewModel.BusinessType.Value;
                toUpdate.City = viewModel.City;
                toUpdate.CompanyName = viewModel.CompanyName;
                toUpdate.OperatingDistance = viewModel.OperatingDistance;
                toUpdate.Phone = Util.ConvertPhoneForStorage(viewModel.Phone);
                toUpdate.PostalCode = viewModel.PostalCode;
                toUpdate.Published = viewModel.Published;
                toUpdate.StateId = viewModel.StateId;
                toUpdate.Website = viewModel.Website;
                toUpdate.SubscriptionStatus = viewModel.Subscribed ? SubscriptionStatus.Paid : SubscriptionStatus.Free;

                if (_service.Update(toUpdate))
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    Util.MapValidationErrors(_service.ValidationDic, this.ModelState);
                }
            }
            rePopViewModel(viewModel);
            return View(viewModel);
        }
 private void rePopViewModel(CompanyProfileEditModel viewModel)
 {
     viewModel.States = _service.GetStates().Select(s => new SelectListItem { Text = s.Abbr, Value = s.Id.ToString(), Selected = viewModel.StateId == s.Id });
     viewModel.BusinessTypes = Util.CreateSelectListFromEnum(typeof(BusinessType), viewModel.BusinessType.Value.ToString());
 }
        // GET: /Admin/Company/Edit/123
        public ActionResult Edit(int id)
        {
            CompanyProfile company = _service.Get(id);

            CompanyProfileEditModel viewModel = new CompanyProfileEditModel
            {
                Address1 = company.Address1,
                Address2 = company.Address2,
                BusinessType = company.BusinessType,
                City = company.City,
                CompanyName = company.CompanyName,
                Id = company.Id,
                OperatingDistance = company.OperatingDistance,
                Phone = Util.ConvertPhoneForDisplay(company.Phone),
                PostalCode = company.PostalCode,
                Published = company.Published,
                StateId = company.StateId.HasValue ? company.StateId.Value : 0,
                Website = company.Website,
                Subscribed = company.SubscriptionStatus == SubscriptionStatus.Free ? false : true
            };

            rePopViewModel(viewModel);
            return View(viewModel);
        }