示例#1
0
        public ActionResult CreateOrUpdate(Employee employee)
        {
            this.employeeTasks.CreateOrUpdate(employee);

            if (employee.IsValid())
            {
                this.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                    "The employee was successfully updated.";
                return this.RedirectToAction("Index");
            }

            var viewModel = new EmployeeFormViewModel
                {
                   AvailableTerritories = this.territoryTasks.GetTerritories(), Employee = employee
                };
            return View(viewModel);
        }
示例#2
0
        public void CreateOrUpdate(Employee employee)
        {
            var employeeToUpdate = employee.Clone();
            employee.Territories.Clear();

            foreach (var territory in employeeToUpdate.Territories)
            {
                employee.Territories.Add(territory);
            }

            if (employee.IsValid())
            {
                this.employeeRepository.DbContext.BeginTransaction();
                this.employeeRepository.SaveOrUpdate(employee);
                this.employeeRepository.DbContext.CommitChanges();
            }
            else
            {
                this.employeeRepository.DbContext.RollbackTransaction();
            }
        }
示例#3
0
        public void RiaCreateOrUpdate(Employee employee, string availableTerritories)
        {
            employee.Territories.Clear();

            foreach (var territory in availableTerritories.Split(','))
            {
                // Depending on how you're accepting user input, better to use NHSearch
                var hydratedTerritory =
                    this.territoryRepository.GetAll().Where(x => x.Description.Trim() == territory.Trim()).FirstOrDefault();

                if (hydratedTerritory != null)
                {
                    employee.Territories.Add(hydratedTerritory);
                }
            }

            // Currently crashes on duplicates, Territories probably should be a hash set and not a list
            if (employee.IsValid())
            {
                this.employeeRepository.DbContext.BeginTransaction();
                this.employeeRepository.SaveOrUpdate(employee);
                this.employeeRepository.DbContext.CommitChanges();
            }
            else
            {
                this.employeeRepository.DbContext.RollbackTransaction();
            }
        }