Пример #1
0
        /// <summary>
        ///   Transfers the employee entity's property values to the DTO.
        ///   Strongly consider Jimmy Bogard's AutoMapper (http://automapper.codeplex.com/) 
        ///   for doing this kind of work in a more automated fashion.
        /// </summary>
        public static EmployeeDto Create(Employee employee)
        {
            if (employee == null)
            {
                return null;
            }

            return new EmployeeDto { Id = employee.Id, FirstName = employee.FirstName, LastName = employee.LastName };
        }
Пример #2
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);
        }
Пример #3
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();
            }
        }
Пример #4
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();
            }
        }