Пример #1
0
        private Result Add(Employee employee)
        {
            _employeeRepository.Setup(e => e.Insert(employee));
            _employeeAppService = new EmployeeAppService(_employeeRepository.Object);

            return(_employeeAppService.Add(employee));
        }
Пример #2
0
        public IActionResult Post([FromBody] EmployeeViewModel employeeViewModel)
        {
            if (!ModelStateValida())
            {
                return(Response());
            }

            _employeeAppService.Add(employeeViewModel);
            return(Response(employeeViewModel));
        }
Пример #3
0
        public ActionResult Create(EmployeeViewModel Employee)
        {
            if (ModelState.IsValid)
            {
                var EmployeeDomain = Mapper.Map <EmployeeViewModel, Employee>(Employee);
                _employeeApp.Add(EmployeeDomain);

                return(RedirectToAction("Index"));
            }
            return(View(Employee));
        }
Пример #4
0
        public ActionResult Create(EmployeeViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (Session["DEPENDENT"] != null)
                    {
                        var deps = (List <DependentDto>)Session["DEPENDENT"];

                        foreach (var depDto in deps)
                        {
                            var dependente = new DependentViewModel();
                            dependente.Name = depDto.Nome;

                            model.Dependents.Add(dependente);
                        }
                    }

                    ViewBag.role = new SelectList(_roleAppService.GetAll(), "RoleId", "Name", model.RoleId);

                    _employeeAppService.Add(model);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.role = new SelectList(_roleAppService.GetAll(), "RoleId", "Name");
                }

                return(View(model));
            }
            catch
            {
                return(View());
            }
        }
 public Task <ObjectResult> Add([FromBody] Employee employee)
 {
     return(_employeeAppService.Add(employee).TaskResult());
 }
Пример #6
0
        public ActionResult Register(Employee model, string[] EmployeesCustom, string[] roles, string returnUrl)
        {
            var isExist = _employeeService.All().FirstOrDefault(x => x.Email == model.Email.ToLower());

            if (isExist == null)
            {
                try
                {
                    model.UserName = model.Email;
                    ModelState.Clear();
                    UpdateModel(model);
                }
                catch
                {
                }
                if (ModelState.IsValid)
                {
                    if (model.Password == model.ConfirmPassword)
                    {
                        try
                        {
                            Employee employee = new Employee();
                            employee.UserName = model.UserName;
                            employee.Email    = model.Email;
                            //employee.BranchCode = model.BranchCode;
                            employee.IsActive = false;

                            WebSecurity.CreateUserAndAccount(model.Email.ToLower(), model.Password);
                            Roles.AddUserToRoles(employee.Email, roles);

                            _employeeService.Add(employee);
                            _employeeService.Save();

                            int id = employee.Id;//_employeeService.All().LastOrDefault().Id;

                            List <string> userbranch = EmployeesCustom.ToList();



                            string UID = Convert.ToString(id);
                            //List<UserBranch> userList = new List<UserBranch>();
                            foreach (var BranchCode in userbranch)
                            {
                                UserBranch userbranchs = new UserBranch();
                                userbranchs.Userid     = UID;
                                userbranchs.BranchCode = BranchCode;
                                //userList.Add(userbranchs);
                                _userbranchService.Add(userbranchs);
                                _userbranchService.Save();
                            }

                            // model.Branchs = userList;
                            //_employeeService.Add(model);

                            // _userbranchService.SaveChanges();

                            //Roles.AddUserToRole(model.Email, "");
                            ViewBag.Roles = roles;

                            ViewBag.BranchCode = new SelectList(_branchService.All().ToList(), "BranchCode", "BranchName");
                            ViewBag.Id         = new SelectList(_employeeService.All().ToList(), "Id", "UserName");

                            return(RedirectToAction("Register"));
                        }
                        catch (MembershipCreateUserException e)
                        {
                            ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("error", "Password doesn't match. Please recheck password");
                    }
                }
            }
            else
            {
                ViewBag.IsAlreadyRegistered = "This User Name is already registered.";
            }
            List <string> allRole = new List <string>();

            foreach (string role in System.Web.Security.Roles.GetAllRoles().ToList())
            {
                allRole.Add(role);
            }
            ViewBag.Roles      = allRole;
            ViewBag.BranchCode = new SelectList(_branchService.All().ToList(), "BranchCode", "BranchName");
            ViewBag.Id         = new SelectList(_employeeService.All().ToList(), "Id", "UserName");
            return(View(model));
        }