Exemple #1
0
        public ActionResult SaveEmployee(Employee e, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
            case "Save Employee":
                if (ModelState.IsValid)
                {
                    EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
                    empBal.SaveEmployee(e);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                    vm.FirstName = e.FirstName;
                    vm.LastName  = e.LastName;
                    vm.Salary    = e.Salary.ToString();

                    vm.FooterData             = new FooterViewModel();
                    vm.FooterData.CompanyName = "StepByStepSchools"; //Can be set to dynamic value
                    vm.FooterData.Year        = DateTime.Now.Year.ToString();
                    vm.UserName = User.Identity.Name;                //New Line
                    //if (e.Salary.HasValue)
                    //    vm.Salary = e.Salary.ToString();
                    //else
                    //    vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                    return(View("CreateEmployee", vm));       // Day 4 Change - Passing e here
                }

            case "Cancel":
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
        public ActionResult SaveEmployee(Employee emp, string BtnSubmit)
        {
            // return emp.FirstName + "|" + emp.LastName + "|" + emp.Salary;
            switch (BtnSubmit)
            {
            case "Save Employee":
                // return Content(emp.FirstName + "|" + emp.LastName + "|" + emp.Salary);
                if (ModelState.IsValid)
                {
                    EmployeeBussinesLayer empBal = new EmployeeBussinesLayer();
                    empBal.SaveEmployee(emp);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                    vm.FirstName = emp.FirstName;
                    vm.LastName  = emp.LastName;
                    if (emp.Salary.HasValue)
                    {
                        vm.Salary = emp.Salary.ToString();
                    }
                    else
                    {
                        vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                    }
                    return(View("CreateEmployee", vm));
                }

            case "Cancel":
                //return RedirectToAction("Index");
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
 public IActionResult Create(CreateEmployeeViewModel model)
 {
     if (ModelState.IsValid)
     {
         string uniqueFileName = null;
         if (model.Photos != null && model.Photos.Count > 0)
         {
             foreach (IFormFile photo in model.Photos)
             {
                 string UploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "UploadedEmployeePhotos");
                 uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                 string FilePath = Path.Combine(UploadsFolder, uniqueFileName);
                 photo.CopyTo(new FileStream(FilePath, FileMode.Create));
             }
         }
         Employee newEmployee = new Employee()
         {
             Name       = model.Name,
             Email      = model.Email,
             Department = model.Department,
             PhotoPath  = uniqueFileName
         };
         _employeeRepository.CreateEmployee(newEmployee);
         return(RedirectToAction("Details", new { id = newEmployee.Id }));
     }
     else
     {
         return(View());
     }
 }
Exemple #4
0
        public IActionResult CreateEmployee(CreateEmployeeViewModel model)
        {
            var employee = new Employee
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Position  = model.Position
            };

            using (var dbContextTransaction = _dbContext.Database.BeginTransaction())
            {
                _dbContext.Employees.Add(employee);

                _dbContext.SaveChanges();

                dbContextTransaction.Commit();
            }

            var employees = _dbContext.Employees.ToList();

            var remoteEmployess = _dbContext.RemoteEmployees
                                  .Where(re => !employees.Where(e => e.FirstName == re.FirstName &&
                                                                e.LastName == re.LastName).Any()).ToList();

            return(View("CreateEmployeeList", new CreateEmployListViewModel {
                RemoteEmployees = remoteEmployess
            }));
        }
        public ActionResult Create(CreateEmployeeViewModel model)
        {
            if (ModelState.IsValid)
            {
                UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
                var user = userManager.FindById(User.Identity.GetUserId());

                ApplicationUser newUser = new ApplicationUser {
                    UserName  = model.Email,
                    Email     = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    CompanyId = user.CompanyId,
                    StartDate = model.StartDate
                };

                string password = System.Web.Security.Membership.GeneratePassword(10, 1);


                userManager.Create(newUser, password);
                ViewBag.password = password;
                return(View("Create", newUser));
            }
            else
            {
                return(View("Create"));
            }
        }
Exemple #6
0
        public ActionResult Create(CreateEmployeeViewModel employee)
        {
            _employeeService.CreateEmployee(new Domain.Employee
            {
                PersonalDetails = new Domain.PersonalDetails
                {
                    FirstName     = employee.FirstName,
                    LastName      = employee.LastName,
                    UMCN          = employee.UMCN,
                    Address       = employee.Address,
                    DateOfBirth   = employee.DateOfBirth,
                    Email         = employee.Email,
                    HomePhoneNum  = employee.HomePhoneNum,
                    MobPhoneNum   = employee.MobPhoneNum,
                    MaritatStatus = employee.MaritatStatus
                },
                EmploymentDetails = new Domain.EmploymentDetails
                {
                    ContractType = employee.ContractType,
                    Wage         = new Domain.Wage(employee.InitialWage, employee.InitialWage, null)
                }
            });

            return(RedirectToAction("List"));
        }
Exemple #7
0
        public ActionResult Create(CreateEmployeeViewModel employee)
        {
            if (ModelState.IsValid)
            {
                var e = new Employee
                {
                    HireDate = employee.HireDate,
                    Name     = employee.Name,
                    Salary   = employee.Salary
                };

                var ne = db.Employee.Add(e);
                db.SaveChanges();

                for (int i = 0; i < employee.Addresses.Count(); i++)
                {
                    this.db.Database.ExecuteSqlCommand(@"INSERT INTO AEMP(ADDRESSNAME,DESCRIPTION,IDEMP) values ({0},{1},{2})", employee.Addresses.ElementAt(i), "Descripcion default", ne.Id);
                }

                for (int i = 0; i < employee.Telephones.Count(); i++)
                {
                    this.db.Database.ExecuteSqlCommand(@"INSERT INTO TELEMP(NUMBER,DESCRIPTION,IDEMP) values ({0},{1},{2})", employee.Telephones.ElementAt(i), "Descripcion default", ne.Id);
                }

                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
Exemple #8
0
        public ActionResult Create(CreateEmployeeViewModel vm)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessFileUpload(vm);
                //string uniqueFileName = null;
                //if (vm.Photo != null)
                //{
                //    string uploadFolder =Path.Combine(_hostingEnvironment.WebRootPath, "images");
                //    uniqueFileName = Guid.NewGuid().ToString() + "_" + vm.Photo.FileName;
                //    string filePath = Path.Combine(uploadFolder, uniqueFileName);

                //    vm.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                //}
                Employee newEmployee = new Employee
                {
                    Name       = vm.Name,
                    Email      = vm.Email,
                    Department = vm.Department,
                    PhotoPath  = uniqueFileName
                };
                _employeeRepository.AddEmployee(newEmployee);
                return(RedirectToAction("Details", new { id = newEmployee.Id }));
                //Employee newEmployee = _employeeRepository.AddEmployee(obj);
                //return RedirectToAction("Details", new { id = newEmployee.Id });
            }
            return(View());
        }
Exemple #9
0
        /// <summary>
        /// Permet de sauvegarder un employé ou revenir à la page d'accueil
        /// </summary>
        /// <param name="e">Employé à enregistrer</param>
        /// <param name="BtnSubmit">Action souhaité</param>
        /// <returns>Soit le salarié enregistré, soit reviens à la page d'accueil</returns>
        public ActionResult SaveEmployee(Employee e, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
            case "Enregistrer":
                if (ModelState.IsValid)
                {
                    EmployeeBusinessLayer empBL = new EmployeeBusinessLayer();
                    empBL.SaveEmployee(e);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    CreateEmployeeViewModel createEmployeeVM = new CreateEmployeeViewModel();
                    createEmployeeVM.FirstName = e.FirstName;
                    createEmployeeVM.LastName  = e.Lastname;
                    if (e.Salary.HasValue)
                    {
                        createEmployeeVM.Salary = e.Salary.ToString();
                    }
                    else
                    {
                        createEmployeeVM.Salary = ModelState["Salary"].Value.AttemptedValue;
                    }
                    //Demander à Emilien pourquoi le RedirectToAction ne garde pas les message alors que le return View oui? Qu'est ce qui est différent?
                    return(View("CreateEmployee", createEmployeeVM));
                }

            case "Annuler":
                return(RedirectToAction("Index"));

            default:
                return(new EmptyResult());
            }
        }
Exemple #10
0
        public IActionResult CreateEmployee(CreateEmployeeViewModel model)
        {
            if (StaticCache.User == null)
            {
                AddNotification(NotificationViewModel.GetWarning("Page Not Accessable", $"Login to access page"));
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                var request = new EmployeeDTO
                {
                    Name           = $"{model.FirstName} {model.LastName}",
                    TIN            = model.TIN,
                    EmployeeTypeId = model.EmployeeType,
                    BirthDate      = model.BirthDate
                };

                var res = _employeeManager.Create(request);
                if (res.IsSuccess)
                {
                    StaticCache.Employees = _employeeManager.GetAll().Take(20);

                    AddNotification(NotificationViewModel.GetSuccess("New Employee Created", $"A new employee with name {request.Name} was Created successfully"));
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ModelState.AddModelError("", $"{res.Message ?? "Unable to login at the moment"}");
                    return(View(nameof(Index), model));
                }
            }

            return(View(nameof(Index), model));
        }
        public ActionResult Create(int departmentId)
        {
            var model = new CreateEmployeeViewModel();

            model.DepartmentId = departmentId;
            return(View(model));
        }
        public ActionResult Create(int DepartmentId)
        {
            var Model = new CreateEmployeeViewModel();

            Model.DepartmentID = DepartmentId;
            return(View());
        }
Exemple #13
0
        public async Task <IActionResult> Create([Bind("EmployeeNumber,FirstName,LastName,CompanyEmail,PersonalEmail,ReportsTo,CanApprove")] CreateEmployeeViewModel model)
        {
            ViewData["Approvers"] = GetApprovers(model.ReportsTo);

            if (ModelState.IsValid)
            {
                try
                {
                    await Mediator.Send(new CreateEmployee_Request
                    {
                        FirstName      = model.FirstName,
                        LastName       = model.LastName,
                        EmployeeNumber = model.EmployeeNumber,
                        CompanyEmail   = model.CompanyEmail,
                        PersonalEmail  = model.PersonalEmail,
                        CreatedBy      = User.Identity.Name,
                        ApproverID     = model.ReportsTo,
                        CanApprove     = model.CanApprove
                    });

                    return(Redirect(Url.Action("Index", "Employees")).WithSuccess("Success", "Added new employee record"));
                }catch (DbUpdateException ex)
                {
                    ErrorResponse.AddError(ex.GetExceptionMessage());
                }catch (Exception ex)
                {
                    ErrorResponse.AddError(ex.GetExceptionMessage());
                }
            }
            return(View(model).WithDanger("Action cannot be completed", ErrorResponse.Message));
        }
Exemple #14
0
        public ActionResult saveEmployee(Employee emp, string btnSubmit)
        {
            switch (btnSubmit)
            {
            case "Save Employee":
                if (ModelState.IsValid)
                {
                    EmployeeService empService = new EmployeeService();
                    empService.SaveEmployee(emp);
                    return(RedirectToAction("getEmployeeListByEntity"));
                }
                else
                {
                    CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                    vm.FirstName = emp.FirstName;
                    vm.LastName  = emp.LastName;
                    if (emp.Salary != 0)
                    {
                        vm.Salary = emp.Salary.ToString();
                    }
                    else
                    {
                        vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                    }
                    return(View("CreateEmployee", vm));    // Day 4 Change - Passing e here
                    //return View("CreateEmployee");
                }

            //return Content(emp.FirstName + " | " + emp.LastName + " | " + emp.Salary);
            case "Cancel":
                return(RedirectToAction("getEmployeeListByEntity"));
            }
            return(new EmptyResult());
        }
Exemple #15
0
        public IActionResult SaveEmployee(Employee employee, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
            case "Save Employee":
                if (ModelState.IsValid)
                {
                    var employeeRepository = new EmployeeRepository();
                    employeeRepository.SaveEmployee(employee);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var createEmployeeVM = new CreateEmployeeViewModel();
                    createEmployeeVM.FirstName = employee.FirstName;
                    createEmployeeVM.LastName  = employee.LastName;
                    if (!employee.Salary.Equals(null))
                    {
                        createEmployeeVM.Salary = employee.Salary.ToString();
                    }
                    else
                    {
                        createEmployeeVM.Salary = ModelState["Salary"].AttemptedValue;
                    }
                    return(View("CreateEmployee", createEmployeeVM));
                }

            case "Cancel":
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
Exemple #16
0
        //public ActionResult Create(Employee employee)
        public ActionResult Create(CreateEmployeeViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = string.Empty; //To avoid same file name
                if (model.Image != null)
                {
                    string uploadFolder = Path.Combine(hostEnv.WebRootPath, "images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;
                    string filePath = Path.Combine(uploadFolder, uniqueFileName);
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        model.Image.CopyTo(stream);
                    }
                }

                Employee newEmployee = new Employee {
                    Name       = model.Name,
                    Email      = model.Email,
                    Department = model.Department,
                    ImagePath  = uniqueFileName
                };

                newEmployee = repository.Create(newEmployee);
                return(RedirectToAction("details", new{ id = newEmployee.Id }));
            }
            return(View());
        }
Exemple #17
0
        public async Task <IActionResult> CreateEmployee(CreateEmployeeViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser employee = new ApplicationUser()
                {
                    UserName  = model.Login,
                    Email     = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                };

                var result = await userManager.CreateAsync(employee, model.Password);

                if (result.Succeeded)
                {
                    return(RedirectToAction("ListEmployees", "Administration"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }

            return(View(model));
        }
        public ActionResult SaveEmployee(Employee e, string BtnSave)
        {
            switch (BtnSave)
            {
            case "Save Employee":
                if (ModelState.IsValid)
                {
                    EmployeeBussinessLayer empbl = new EmployeeBussinessLayer();
                    empbl.SaveEmployee(e);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    // return View("CreateEmployee");

                    // to maintain data on validation
                    CreateEmployeeViewModel cevm = new CreateEmployeeViewModel();
                    cevm.FiName = e.FName;
                    cevm.LaName = e.LName;
                    if (e.Salary.HasValue)
                    {
                        cevm.Salary1 = e.Salary.ToString();
                    }
                    else
                    {
                        cevm.Salary1 = ModelState["Salary"].Value.AttemptedValue;
                    }
                    return(View("CreateEmployee", cevm));
                }

            case "Cancel":
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
Exemple #19
0
        private string GetUniqueName(CreateEmployeeViewModel model, string existingFileName = null)
        {
            string uniqueFileName = null;

            if (model.Photos != null && model.Photos.Count > 0)
            {
                foreach (var photo in model.Photos)
                {
                    string uploadDiroctory = Path.Combine(_webHostingEnvironment.WebRootPath, "img");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                    string filePath = Path.Combine(uploadDiroctory, uniqueFileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        photo.CopyTo(fileStream);
                    }
                }
                if (existingFileName != null)
                {
                    string fileDir = Path.Combine(_webHostingEnvironment.WebRootPath, "img", existingFileName);
                    System.IO.File.Delete(fileDir);
                }
            }
            else
            {
                uniqueFileName = existingFileName;
            }

            return(uniqueFileName);
        }
Exemple #20
0
        public ActionResult SaveEmployee(Employee e)
        {
            if (ModelState.IsValid)
            {
                EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
                empBal.SaveEmployee(e);

                return(RedirectToAction("Index"));
            }
            else
            {
                CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                vm.FirstName = e.FirstName;
                vm.LastName  = e.LastName;

                vm.Salary = e.Salary.ToString();

                //vm.FooterData = new FooterViewModel()
                //{
                //    CompanyName = "CompanyName",
                //     Year = DateTime.Now.Year.ToString()
                //};

                //vm.UserName = User.Identity.Name;

                return(View("CreateEmployee", vm));
            }
            //return new EmptyResult();
        }
Exemple #21
0
        public ActionResult CreateEmployee()
        {
            var model = new CreateEmployeeViewModel();

            model.Roles = EmployeeRoles;
            return(View(model));
        }
        public ActionResult AddNew()
        {
            CreateEmployeeViewModel employeeListViewModel = new CreateEmployeeViewModel();

            employeeListViewModel.UserName = User.Identity.Name;
            return(View("CreateEmployee", employeeListViewModel));
        }
        public ActionResult SaveEmployee(Employee e, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
            case "Save Employee":
                if (ModelState.IsValid)
                {
                    EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
                    empBal.SaveEmployee(e);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                    vm.FirstName = e.FirstName;
                    vm.LastName  = e.LastName;
                    if (e.Salary.HasValue)
                    {
                        vm.Salary = e.Salary.ToString();
                    }
                    else
                    {
                        vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                    }
                    vm.UserName = User.Identity.Name;
                    return(View("CreateEmployee", vm));
                }

            case "Cancel":
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
Exemple #24
0
        public async Task <IActionResult> Create(CreateEmployeeViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Employee employee;
                if (viewModel.EmployeeTypeValue == EmployeeType.Manager.Value)
                {
                    employee = new Manager();
                }
                else if (viewModel.EmployeeTypeValue == EmployeeType.Sales.Value)
                {
                    employee = new Sales();
                }
                else
                {
                    employee = new Worker();
                }
                employee.Name           = viewModel.Name;
                employee.BasicSalary    = viewModel.BasicSalary;
                employee.DateDeployment = viewModel.DateDeployment;
                employee.ChiefId        = viewModel.ChiefId;
                EmployeeRepository.Create(employee);
                return(RedirectToAction("Index"));
            }
            await ConfigureEmployeeViewModel(viewModel);

            return(View(viewModel));
        }
        public ActionResult SaveEmployee(Employee e, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
            case "Save Employee":
                if (ModelState.IsValid)
                {
                    var empBal = new EmployeeBusinessLayer();
                    empBal.SaveEmployee(e);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var vm = new CreateEmployeeViewModel
                    {
                        FirstName = e.FirstName,
                        LastName  = e.LastName,
                    };
                    if (e.Salary.HasValue)
                    {
                        vm.Salary = e.Salary.ToString();
                    }
                    else
                    {
                        vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                    }
                    return(View("CreateEmployee", vm));    // Day 4 Change - Passing e here
                }

            case "Cancel":
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
        public ActionResult SaveEmployee(Employee e, string BtnSubmit)
        {
            switch (BtnSubmit)
            {
            case "Save Employee":
                if (ModelState.IsValid)
                {
                    EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
                    empBal.SaveEmployee(e);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    CreateEmployeeViewModel vm = new CreateEmployeeViewModel();

                    //vm.FooterData = new FooterViewModel();
                    //vm.FooterData.CompanyName = "StepByStepSchools";
                    //vm.FooterData.Year = DateTime.Now.Year.ToString();
                    //vm.UserName = User.Identity.Name;

                    return(View("CreateEmployee", vm));
                }

            case "Cancel":
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
Exemple #27
0
        public ActionResult SaveEmployee(Employee e, string btnSubmit)
        {
            switch (btnSubmit)
            {
            case "Save":    //点击的是保存按钮
                if (ModelState.IsValid && e.Salary != null)
                {
                    EmployeeBusinessLayer ebl = new EmployeeBusinessLayer();
                    ebl.SaveEmployee(e);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    CreateEmployeeViewModel cevm = new CreateEmployeeViewModel();
                    cevm.FirstName = e.FirstName;
                    cevm.LastName  = e.LastName;
                    if (e.Salary.HasValue)
                    {
                        cevm.Salary = e.Salary.ToString();
                    }
                    else
                    {
                        cevm.Salary = ModelState["Salary"].Value.AttemptedValue;
                    }

                    return(View("CreateEmployee", cevm));
                }

            case "Cancel":    //点击取消按钮,则取消并返回Index
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
        public ActionResult SaveEmployee(Employee employee, string btnSubmit)
        {
            switch (btnSubmit)
            {
            case "Save Employee":
                //return Content(employee.FirstName + "|" + employee.LastName + "|" + employee.Salary);
                if (ModelState.IsValid)
                {
                    EmployeeBusinessLayer employeeBusinessLayer = new EmployeeBusinessLayer();
                    employeeBusinessLayer.SavEmployee(employee);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    CreateEmployeeViewModel createEmployeeViewModel = new CreateEmployeeViewModel();
                    //{
                    //    FirstName = employee.FirstName,
                    //    LastName = employee.LastName,
                    //    Salary = employee.Salary.HasValue?employee.Salary.ToString():ModelState["Salary"].Value.AttemptedValue
                    //};
                    return(View("CreateEmployee", createEmployeeViewModel));
                }

            case "Cancel":
                return(RedirectToAction("Index"));
            }
            return(new EmptyResult());
        }
        public ActionResult Create(CreateEmployeeViewModel model)
        {
            using (SqlConnection conn = Connection)

            {
                if (ModelState.IsValid)
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())

                    {
                        cmd.CommandText = @"INSERT INTO Employee (FirstName, LastName, IsSuperVisor, DepartmentId) VALUES (@firstName, @lastName, @isSuperVisor, @departmentId)";

                        cmd.Parameters.Add(new SqlParameter("@firstName", model.employee.FirstName));
                        cmd.Parameters.Add(new SqlParameter("@lastName", model.employee.LastName));
                        cmd.Parameters.Add(new SqlParameter("@departmentId", model.employee.DepartmentId));
                        cmd.Parameters.Add(new SqlParameter("@isSuperVisor", model.employee.IsSuperVisor));

                        cmd.ExecuteNonQuery();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                else
                {
                    CreateEmployeeViewModel createEmployeeViewModel = new CreateEmployeeViewModel(_config.GetConnectionString("DefaultConnection"));



                    return(View(createEmployeeViewModel));
                }
            }
        }
Exemple #30
0
        public ActionResult AddNew()
        {
            CreateEmployeeViewModel employeeListViewModel = new CreateEmployeeViewModel();


            return(View("CreateEmployee", employeeListViewModel));
        }
Exemple #31
0
 public Employee CreateEmployeeViewModelToEmployee(CreateEmployeeViewModel createEmployeeViewModel, Company employeeCompany)
 {
     return new Employee
     {
         Name = createEmployeeViewModel.Name,
         LastName = createEmployeeViewModel.LastName,
         Email = createEmployeeViewModel.Email,
         Phone = createEmployeeViewModel.Phone,
         Company = employeeCompany
     };
 }
        public void Given_A_Valid_Employee_Data_When_Creting_Employee_With_Login_Should_Create_Both_In_Database_And_Send_An_Email_To_Created_Employee()
        {
            var createEmployeeViewModel = new CreateEmployeeViewModel
            {
                Name = "Quezia",
                LastName = "Mello",
                Email = "*****@*****.**",
                Phone = "(21) 98802-3931",
                GenerateLogin = true
            };

            _membershipServiceMock.Setup(x => x.GetLoggedUser("teste")).Returns(UserDummies.ReturnOneMjrActiveUser());

            _flexRoleStoreMock.Setup(x => x.GetAllRoles()).Returns(RoleDummies.ReturnAllRoles());

            var result = _employeeController.Create(createEmployeeViewModel) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public ActionResult Create(CreateEmployeeViewModel employee)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var employeeCompany = _employeeLoginFacade.GetLoggedUser(User.Identity.Name).Employee.Company;

                    if (employee.GenerateLogin)
                    {
                        if (String.IsNullOrEmpty(employee.Email))
                        {
                            ModelState.AddModelError("", "Para criar um login para o funcionário, preencha o E-mail do mesmo.");
                            return View(employee);
                        }

                        _employeeLoginFacade.CreateEmployeeAndLogin(employee, employeeCompany);
                    }
                    else
                        _employeeLoginFacade.CreateEmployee(employee, employeeCompany);

                    return RedirectToAction("Index");
                }

                return View(employee);
            }
            catch (EmployeeWithExistentEmailException ex)
            {
                ModelState.AddModelError("EmailExists", ex.Message);
                return View(employee);
            }
            catch
            {
                return View();
            }
        }
        public void Given_An_Employee_With_Same_Email_Data_Of_Another_When_Creating_Employee_With_Login_Should_Return_Message_Error()
        {
            var createEmployeeViewModel = new CreateEmployeeViewModel
            {
                Name = "Quezia",
                LastName = "Mello",
                Email = "*****@*****.**",
                GenerateLogin = true
            };

            _emailServiceMock.Setup(x => x.SendFirstLoginToEmployee(It.IsAny<string>(), createEmployeeViewModel.Email, createEmployeeViewModel.Name, createEmployeeViewModel.LastName));
            _flexMembershipRepositoryMock.Setup(x => x.GetUserByUsername(It.IsAny<string>())).Returns(UserDummies.ReturnOneMjrActiveUser);

            _principalMock.Setup(x => x.Identity.Name).Returns(createEmployeeViewModel.Email);

            _employeeController.ControllerContext = _controllerContextMock.Object;

            var result = _employeeController.Create(createEmployeeViewModel);

            Assert.IsNotNull(result);
            Assert.AreEqual("Este E-mail já existe para outro funcionário", _employeeController.ModelState["EmailExists"].Errors[0].ErrorMessage);

            _flexMembershipRepositoryMock.VerifyAll();
        }
 public ActionResult AddNew()
 {
     CreateEmployeeViewModel employeeListViewModel = new CreateEmployeeViewModel();
     return View("CreateEmployee", employeeListViewModel);
 }
 public ActionResult SaveEmployee(Employee e, string BtnSubmit)
 {
     switch (BtnSubmit)
     {
         case "Save Employee":
             if (ModelState.IsValid)
             {
                 EmployeeBusinessLayer empBal = new EmployeeBusinessLayer();
                 empBal.SaveEmployee(e);
                 return RedirectToAction("Index");
             }
             else
             {
                 CreateEmployeeViewModel vm = new CreateEmployeeViewModel();
                 vm.FirstName = e.FirstName;
                 vm.LastName = e.LastName;
                 if (e.Salary > 0)
                 {
                     vm.Salary = e.Salary.ToString();
                 }
                 else
                 {
                     vm.Salary = ModelState["Salary"].Value.AttemptedValue;
                 }
                 return View("CreateEmployee", vm); // Day 4 Change - Passing e here
             }
         case "Cancel":
             return RedirectToAction("Index");
     }
     return new EmptyResult();
 }
        public ActionResult CreateEmployee(CreateEmployeeViewModel cevm)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "There's something wrong! Please check what you've entered.");
                return View(cevm);
            }

            User loggedUser = db.Users.Where(u => u.UserName == User.Identity.Name).First();
            Employee loggedEmployee = db.Employees
                .Where(e => e.UserId == loggedUser.Id)
                .FirstOrDefault();

            User user = db.Users.Create();
            user.FirstName = cevm.FirstName;
            user.LastName = cevm.LastName;
            user.Birthdate = cevm.Birthdate;
            user.UserName = cevm.Username;
            user.Email = cevm.Email;
            user.CreatedOn = DateTime.Now;

            var result = userManager.Create(user, cevm.TemporaryPassword);

            Employee employee = db.Employees.Create();
            employee.BranchId = loggedEmployee.BranchId;
            employee.JobTypeId = cevm.JobTypeId;
            employee.UserId = user.Id;

            db.Employees.Add(employee);
            db.SaveChanges();

            return RedirectToAction("ManageEmployees", "Branch");
        }
Exemple #38
0
 public ActionResult AddNew()
 {
     CreateEmployeeViewModel v = new CreateEmployeeViewModel();
     return PartialView("CreateEmployee",v);
 }
        public ActionResult CreateEmployee()
        {
            CreateEmployeeViewModel cevm = new CreateEmployeeViewModel();
            List<SelectListItem> sli = new List<SelectListItem>();

            foreach (JobType jt in db.JobTypes
                .Where(jt => jt.AccessPrivilege != AccessPrivilege.Administrator &&
                        jt.AccessPrivilege != AccessPrivilege.Owner)
                .ToList())
            {
                sli.Add(new SelectListItem
                {
                    Text = jt.Name,
                    Value = jt.Id.ToString()
                });
            }

            cevm.Birthdate = DateTime.Now;
            cevm.JobTypes = sli;
            cevm.TemporaryPassword = System.Web.Security.Membership.GeneratePassword(8,0);

            return View(cevm);
        }
        public void Given_A_Valid_Employee_Data_When_Creating_Employee_With_Login_Option_Ture_Should_Create_Both_In_Database_And_Send_An_Email_To_Created_Employee()
        {
            var createEmployeeViewModel = new CreateEmployeeViewModel
            {
                Name = "Quezia",
                LastName = "Mello",
                Email = "*****@*****.**",
                GenerateLogin = true
            };

            _flexRoleStoreMock.Setup(x => x.GetAllRoles()).Returns(RoleDummies.ReturnAllRoles());
            _emailServiceMock.Setup(x => x.SendFirstLoginToEmployee(It.IsAny<string>(), createEmployeeViewModel.Email, createEmployeeViewModel.Name, createEmployeeViewModel.LastName));
            _employeeRepositoryMock.Setup(x => x.Add(It.IsAny<Employee>()));
            _flexMembershipRepositoryMock.Setup(x => x.Add(It.IsAny<User>()));
            _flexMembershipRepositoryMock.SetupSequence(x => x.GetUserByUsername(It.IsAny<string>()))
                .Returns(UserDummies.ReturnOneMjrActiveUser())
                .Returns(null);

            _principalMock.Setup(x => x.Identity.Name).Returns(createEmployeeViewModel.Email);

            _employeeController.ControllerContext = _controllerContextMock.Object;

            var result = _employeeController.Create(createEmployeeViewModel) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.RouteValues["action"]);

            _flexRoleStoreMock.VerifyAll();
            _emailServiceMock.VerifyAll();
            _employeeRepositoryMock.VerifyAll();
            _flexMembershipRepositoryMock.VerifyAll();
        }