コード例 #1
0
        public virtual ActionResult Add()
        {
            var user = _userByIdQuery.WithUserId(CurrentUserId).Execute();
            var statuses = _serviceFactory.GetService<LeadStatusesAvailableForCompaniesQuery>().Execute();
            var model = new EditCompanyViewModel
            {
                JobSearchId = Convert.ToInt32(user.LastVisitedJobSearchId),
                AvailableLeadStatuses = _serviceFactory.GetService<LeadStatusesAvailableForCompaniesQuery>().Execute()
            };

            return View(MVC.Company.Views.Edit, model);
        }
コード例 #2
0
        public virtual ActionResult Edit(EditCompanyViewModel model)
        {
            Company company;

            try
            {
                // Determine if this is a new company or not
                if (model.Id == 0)
                {
                    company = new CreateCompanyCommand(_serviceFactory).WithJobSearch(model.JobSearchId)
                                                                          .SetName(model.Name)
                                                                          .SetCity(model.City)
                                                                          .SetIndustry(model.Industry)
                                                                          .SetMetroArea(model.MetroArea)
                                                                          .SetNotes(model.Notes)
                                                                          .SetPhone(model.Phone)
                                                                          .SetState(model.State)
                                                                          .SetZip(model.Zip)
                                                                          .SetWebsite(model.Website)
                                                                          .CalledByUserId(CurrentUserId)
                                                                          .Execute();
                }
                else
                {
                    company = new EditCompanyCommand(_serviceFactory).WithCompanyId(model.Id)
                                                                          .SetName(model.Name)
                                                                          .SetCity(model.City)
                                                                          .SetIndustry(model.Industry)
                                                                          .SetMetroArea(model.MetroArea)
                                                                          .SetNotes(model.Notes)
                                                                          .SetPhone(model.Phone)
                                                                          .SetState(model.State)
                                                                          .SetZip(model.Zip)
                                                                          .SetLeadStatus(model.LeadStatus)
                                                                          .SetWebsite(model.Website)
                                                                          .RequestedByUserId(CurrentUserId)
                                                                          .Execute();
                }

                return RedirectToAction(MVC.Company.Details(company.Id));
            }

            catch (ValidationException ex)
            {
                foreach (var error in ex.Errors)
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);

                model.AvailableLeadStatuses = _serviceFactory.GetService<LeadStatusesAvailableForCompaniesQuery>().Execute();
                return View(model);
            }
        }