Esempio n. 1
0
        public void TransformCustomerToEmployee(CreateEmployeeBindingModel model)
        {
            Customer customer = this.Context.Customers.Find(model.Id);
            Employee employee = Mapper.Map <Employee>(model);

            employee.ApplicationUser = customer.ApplicationUser;

            this.Context.Customers.Remove(customer);
            this.Context.Employees.Add(employee);
            this.Context.SaveChanges();
        }
        public ActionResult CreateEmployee(
            [Bind(Include = "Id, FirstName, LastName, Salary, Address, ApplicationUser")] CreateEmployeeBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                this.service.TransformCustomerToEmployee(model);
                var userId = model.ApplicationUser.Id;
                UserManager.AddToRole(userId, "Employee");
                UserManager.RemoveFromRole(userId, "Customer");
                return(this.RedirectToAction("Index"));
            }

            return(this.RedirectToAction("CreateEmployee", "Administrator", new { id = model.Id }));
        }