public static string CreateUser(string firstName, string lastName, string emailAddress, string shortName, string title, string department, string description, string office, string country, string phone, string officePhone, string address, string zipCode, string state, string city, string reportsTo, string password)
        {
            EmployeeCreateModel Employee = new EmployeeCreateModel
            {
                FirstName    = firstName,
                LastName     = lastName,
                EmailAddress = emailAddress,
                ShortName    = shortName,
                Title        = title,
                Department   = department,
                Description  = description,
                Office       = office,
                Country      = country,
                Phone        = phone,
                OfficePhone  = officePhone,
                Address      = address,
                ZipCode      = zipCode,
                State        = state,
                City         = city,
                ReportsTo    = reportsTo,
                Password     = password
            };

            return("");
        }
        // GET: Employees/Create
        public ActionResult Create()
        {
            DepartmentRepository departmentRepo = new DepartmentRepository();
            var departments = departmentRepo.GetAllDepartments().Select(d => new SelectListItem
            {
                Text  = d.Name,
                Value = d.Id.ToString()
            }).ToList();

            ComputerRepository computerRepo = new ComputerRepository();
            var computers = computerRepo.GetAvailableComputers().Select(d => new SelectListItem
            {
                Text  = $"{d.Make} {d.Model}",
                Value = d.Id.ToString()
            }).ToList();


            var viewModel = new EmployeeCreateModel()
            {
                Employee    = new Employee(),
                Departments = departments,
                Computers   = computers
            };

            return(View(viewModel));
        }
예제 #3
0
        public IActionResult RegisterEmployee(EmployeeCreateModel employee)
        {
            if (ModelState.IsValid)
            {
                string salt           = PasswordHashingLogic.GenerateSalt();
                string PasswordHash   = PasswordHashingLogic.GeneratePasswordHash(employee.Password, salt);
                string uniqueFileName = null;
                if (employee.ProfilePicture != null)
                {
                    string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "img", "ProfilePictures");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + employee.ProfilePicture.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    employee.ProfilePicture.CopyTo(new FileStream(filePath, FileMode.Create));
                }
                EmployeeProcessor.CreateEmployee(
                    employee.Firstname,
                    employee.Prefix,
                    employee.Lastname,
                    employee.City,
                    employee.Postalcode,
                    employee.Address,
                    uniqueFileName,
                    employee.Email,
                    employee.Phone,
                    salt,
                    PasswordHash,
                    employee.Profession,
                    employee.Role.ToString()
                    );
                return(RedirectToAction("ViewEmployees", "Employee"));
            }

            return(View());
        }
예제 #4
0
        public static void PostEnterprise(EnterpriseCreateModel model)
        {
            var request    = new EnterpriseRequestHandler();
            var enterprise = new EnterpriseCreateModel();

            enterprise.Name = model.Name;
            enterprise.EstablishmentYear = model.EstablishmentYear;
            enterprise.Employees         = new List <EmployeeCreateModel>();
            if (model.Employees != null)
            {
                var list = model.Employees.ToList();
                for (int i = 0; i < model.Employees.Count; ++i)
                {
                    var employee = new EmployeeCreateModel();
                    employee.Firstname   = list[i].Firstname;
                    employee.Lastname    = list[i].Lastname;
                    employee.DateOfBirth = list[i].DateOfBirth;
                    employee.JobTitle    = list[i].JobTitle;
                    enterprise.Employees.Add(employee);
                }
            }
            var res = request.CreateCompany(enterprise).Result;

            Console.WriteLine(res);
        }
예제 #5
0
        public async Task <int> CreateEmployee(EmployeeCreateModel model)
        {
            var garage = await this.dbContext.Garages.FirstOrDefaultAsync(x => x.Id == model.GarageId);

            var employee = new Employee()
            {
                UserId = model.UserId,
                Name   = model.UserName,
                Role   = model.Role,
                Garage = garage
            };

            var departmet = await this.dbContext.Departments.FirstOrDefaultAsync(d => d.Id == model.DepartmentId);

            departmet.Employees.Add(employee);
            garage.Employees.Add(employee);

            this.dbContext.Update(garage);
            this.dbContext.Update(departmet);
            this.dbContext.Add(employee);

            await this.dbContext.SaveChangesAsync();

            return(employee.Id);
        }
예제 #6
0
        public DefaultApiResponse ImportEmployee(EmployeeCreateModel employee, string token, out BusinessRulesApiResponse businessRulesApiResponse)
        {
            var _data = JsonConvert.SerializeObject(employee, Newtonsoft.Json.Formatting.None,
                                                    new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            var _address = ApiHelper.Instance.SiteUrl + ApiHelper.Instance.EmployeeCreateEndpoint;

            businessRulesApiResponse = null;

            try
            {
                var _jsonResult = ApiHelper.Instance.WebClient(token).UploadString(_address, "POST", _data);

                if (_jsonResult != "null")
                {
                    return(new DefaultApiResponse(200, "OK", new string[] { }));
                }

                return(new DefaultApiResponse(500, "Internal Application Error: Fail to Import Employee", new string[] { }));
            }
            catch (WebException _webEx)
            {
                using StreamReader _r = new StreamReader(_webEx.Response.GetResponseStream());
                string _responseContent = _r.ReadToEnd();

                return(ApiHelper.Instance.ProcessApiResponseContent(_webEx, _responseContent, out businessRulesApiResponse));
            }
        }
예제 #7
0
        public async Task <ActionResult> CreateAsync([FromBody] EmployeeCreateModel employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            EmployeeCreateServiceModel employeeToCreate = new EmployeeCreateServiceModel
            {
                FirstName       = employee.FirstName,
                LastName        = employee.LastName,
                Salary          = employee.Salary,
                ExperienceLevel = employee.ExperienceLevel,
                StartingDate    = employee.StartingDate,
                VacationDays    = employee.VacationDays,
                Image           = employee.Image,
                OfficeIds       = employee.OfficeIds
            };

            //TODO: Fix the image problem.
            //var file = Request.Form.Files[0];

            int createdEmployeeId = await employeesService
                                    .AddAsync(employeeToCreate);

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = createdEmployeeId }));
        }
예제 #8
0
        public void Add(EmployeeCreateModel employeeModel, string email)
        {
            EmployeeRole role = _context.EmployeeRole.FirstOrDefault(r => r.Owner == email && r.Id == employeeModel.RoleId);

            if (role == null)
            {
                throw new Exception("No permission!!!");
            }
            Employee checkId = _context.Employee.FirstOrDefault(e => e.EmployeeCompanyId == employeeModel.EmployeeCompanyId && e.Owner == email);

            if (checkId != null)
            {
                throw new Exception("Id Exist!!!");
            }
            Employee employee = new Employee()
            {
                EmployeeCompanyId = employeeModel.EmployeeCompanyId,
                FullName          = employeeModel.FullName,
                RoleId            = employeeModel.RoleId,
                Owner             = email,
                Manpower          = employeeModel.Manpower,
                Active            = true
            };

            _context.Add(employee);
            _context.SaveChanges();
        }
        // GET: Employees/Create
        public ActionResult Create()
        {
            var departments = GetDepartments().Select(d => new SelectListItem
            {
                Text  = d.Name,
                Value = d.Id.ToString()
            }).ToList();

            var isSupervisor = GetIsSupervisor().Select(d => new SelectListItem
            {
                Text  = d.ToString(),
                Value = d.ToString()
            }).ToList();

            var computers = GetComputers(-1).Select(d => new SelectListItem
            {
                Text  = d.Model,
                Value = d.Id.ToString()
            }).ToList();

            var viewModel = new EmployeeCreateModel
            {
                Employee     = new Employee(),
                Departments  = departments,
                IsSupervisor = isSupervisor,
                Computers    = computers
            };

            return(View(viewModel));
        }
예제 #10
0
        public IActionResult Create(EmployeeCreateModel model)
        {
            var employee = new Employee()
            {
                EmployeeId  = model.EmployeeId,
                Name        = model.Name,
                Address     = model.Address,
                CompanyName = model.CompanyName,
                Designation = model.Designation,
                Salary      = model.Salary
            };

            _dbContext.Employees.Add(employee);
            try
            {
                if (_dbContext.SaveChanges() > 0)
                {
                    TempData["Message"] = model.Name + "added successfully.";
                }
                else
                {
                    TempData["Errors"] = "Something went wrong, please contact administrator.";
                }
            }
            catch (Exception ex)
            {
                TempData["Errors"] = ex.Message;
            }
            return(RedirectToAction("Create"));
        }
예제 #11
0
        public IActionResult Save([FromBody] EmployeeCreateModel model)
        {
            var employee = new tblEmployee()
            {
                EmployeeID      = model.EmployeeID,
                EmployeeName    = model.EmployeeName,
                PhoneNumber     = model.PhoneNumber,
                SkillID         = model.SkillID,
                YearsExperience = model.YearsExperience
            };

            if (model.EmployeeID == 0)
            {
                _employeeDbContext.tblEmployees.Add(employee);
            }
            else
            {
                _employeeDbContext.tblEmployees.Update(employee);
            }

            if (_employeeDbContext.SaveChanges() > 0)
            {
                TempData["Message"] = "Employee has been added successfully.";
            }
            else
            {
                TempData["Message"] = "Something went wrong, please contact administrator.";
            }
            ViewBag.Skills = GetSkill();
            return(new JsonResult(new { status = 1 }));
            //return RedirectToAction(nameof(Index));
            //return View(new EmployeeCreateModel());
        }
예제 #12
0
        public IActionResult Create(EmployeeCreateModel model)
        {
            var employee = new tblEmployee()
            {
                EmployeeID      = model.EmployeeID,
                EmployeeName    = model.EmployeeName,
                PhoneNumber     = model.PhoneNumber,
                SkillID         = model.SkillID,
                YearsExperience = model.YearsExperience
            };

            _dbcontext.tblEmployees.Add(employee);

            try
            {
                if (_dbcontext.SaveChanges() > 0)
                {
                    TempData["Message"] = "Employee has been added successfully.";
                }
                else
                {
                    TempData["Error"] = "Something went wrong, please contact administrator.";
                }
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
            }

            return(RedirectToAction("Create"));
        }
예제 #13
0
        public async Task <ActionResult> EditAsync(int id, [FromBody] EmployeeCreateModel employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!await employeesService.ExistsAsync(id))
            {
                return(NotFound());
            }

            EmployeeCreateServiceModel employeeToCreate = new EmployeeCreateServiceModel
            {
                Id              = id,
                FirstName       = employee.FirstName,
                LastName        = employee.LastName,
                Salary          = employee.Salary,
                ExperienceLevel = employee.ExperienceLevel,
                StartingDate    = employee.StartingDate,
                VacationDays    = employee.VacationDays,
                Image           = employee.Image
            };

            await employeesService.EditAsync(employeeToCreate);

            return(NoContent());
        }
예제 #14
0
        public ActionResult EmployeeCreate(int id)
        {
            ViewBag.Message = "Create Employee";

            var data = LoadSpecificRequest(id);

            EmployeeCreateModel employeeRequest = new EmployeeCreateModel();

            foreach (var row in data)
            {
                employeeRequest.FirstName    = row.FirstName;
                employeeRequest.LastName     = row.LastName;
                employeeRequest.EmailAddress = row.EmailAddress;
                employeeRequest.Title        = row.Title;
                employeeRequest.Department   = row.Department;
                employeeRequest.Description  = row.Description;
                employeeRequest.Office       = row.Office;
                employeeRequest.Country      = row.Country;
                employeeRequest.Phone        = row.Phone;
                employeeRequest.OfficePhone  = row.OfficePhone;
                employeeRequest.Address      = row.Address;
                employeeRequest.ZipCode      = row.ZipCode;
                employeeRequest.State        = row.State;
                employeeRequest.City         = row.City;
                employeeRequest.ReportsTo    = row.ReportsTo;
            }

            return(View(employeeRequest));
        }
        public ActionResult CreateEmployee(EmployeeCreateModel employeeCreateModel, int academicDegreeTitle, int academicTitleName)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var employeeDTO = new EmployeeDTO {
                        FirstName           = employeeCreateModel.FirstName,
                        LastName            = employeeCreateModel.LastName,
                        Patronymic          = employeeCreateModel.Patronymic,
                        AcademicDegreeDTOId = academicDegreeTitle,
                        AcademicTitleDTOId  = academicTitleName
                    };

                    employeeService.CreateEmployee(employeeDTO);

                    TempData["message"] = string.Format("Сотрудник был добавлен");

                    return(RedirectToAction("index"));
                }
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError(ex.Property, ex.Message);
            }

            return(View(employeeCreateModel));
        }
        public ActionResult Create(EmployeeCreateModel model)
        {
            try
            {
                var imageName = string.Empty;

                if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
                {
                    var EmpPhoto = System.Web.HttpContext.Current.Request.Files["file"];
                    if (EmpPhoto.ContentLength > 0)
                    {
                        var profileName = Path.GetFileName(EmpPhoto.FileName);
                        var ext         = Path.GetExtension(EmpPhoto.FileName);
                        imageName = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ext;
                        var comPath = Server.MapPath("/Images/") + imageName;
                        EmpPhoto.SaveAs(comPath);
                    }
                }
                else
                {
                    imageName = model.EmployeePhoto;
                }

                var dbContext = new ExcellenceITEntities();
                var datamodel = new TBL_Employee
                {
                    CityID        = model.CityID,
                    StateID       = model.StateID,
                    Pincode       = model.Pincode,
                    CountryID     = model.CountryID,
                    Department    = model.Department,
                    Email         = model.Email,
                    EmpID         = model.EmpID,
                    FirstName     = model.FirstName,
                    LastName      = model.LastName,
                    Gender        = model.Gender,
                    Hobbies       = model.Hobbies,
                    Phone         = model.Phone,
                    DOB           = model.DOB,
                    EmployeePhoto = imageName
                };

                if (model.EmpID > 0)
                {
                    dbContext.Entry(datamodel).State = System.Data.Entity.EntityState.Modified;
                    TempData["Message"] = "Emplyoyee Updated Suceessfully";
                }
                else
                {
                    dbContext.TBL_Employee.Add(datamodel);
                    TempData["Message"] = "Emplyoyee Added Suceessfully";
                }
                dbContext.SaveChanges();
                return(Json(new { isSuccess = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new { isSuccess = false }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #17
0
        public void Validate_When_Department_Not_Is_Null_Or_Empty_Should_Return_True(
            EmployeeCreateModel employeeCreateModel,
            EmployeeCreateModelValidator sut)
        {
            employeeCreateModel.Department = "My Department";

            sut.ShouldNotHaveValidationErrorFor(e => e.Department, employeeCreateModel);
        }
        public async Task <IActionResult> Create()
        {
            var employee = await this.employeeData.GetEmployee();

            EmployeeCreateModel model = new EmployeeCreateModel();

            return(View(model));
        }
예제 #19
0
        public void Validate_When_Department_Is_Null_Or_Empty_Should_Return_False(
            EmployeeCreateModel employeeCreateModel,
            EmployeeCreateModelValidator sut)
        {
            employeeCreateModel.Department = null;

            sut.ShouldHaveValidationErrorFor(e => e.Department, employeeCreateModel);
        }
예제 #20
0
        public void Validate_When_Email_Is_Valid_Should_Return_True(
            EmployeeCreateModel employeeCreateModel,
            EmployeeCreateModelValidator sut)
        {
            employeeCreateModel.Email = "*****@*****.**";

            sut.ShouldNotHaveValidationErrorFor(e => e.Email, employeeCreateModel);
        }
예제 #21
0
        public void Validate_When_Email_Is_Invalid_Should_Return_False(
            EmployeeCreateModel employeeCreateModel,
            EmployeeCreateModelValidator sut)
        {
            employeeCreateModel.Email = "teste";

            sut.ShouldHaveValidationErrorFor(e => e.Email, employeeCreateModel);
        }
예제 #22
0
        public void Validate_When_Name_Not_Is_Null_Or_Empty_Should_Return_True(
            EmployeeCreateModel employeeCreateModel,
            EmployeeCreateModelValidator sut)
        {
            employeeCreateModel.Name = "My name";

            sut.ShouldNotHaveValidationErrorFor(e => e.Name, employeeCreateModel);
        }
        public async Task <ActionResult <int> > Create(EmployeeCreateModel model)
        {
            var userId = this.User.GetId();

            var result = await this.employeeService.CreateEmployee(model);

            return(Created(nameof(this.Create), result));
        }
        public async Task <EmployeeResponseModel> CreateAsync(EmployeeCreateModel model)
        {
            var newEmployee     = _mapper.Map <Employee>(model);
            var createdEmployee = await _employeeService.CreateAsync(newEmployee);

            var createdUser = await _accountService.CreateAsync(createdEmployee);

            return(_mapper.Map <EmployeeResponseModel>(createdEmployee));
        }
예제 #25
0
        public async Task <IActionResult> Post(EmployeeCreateModel model)
        {
            var createdEmployee = await _employeeService.CreateAsync(model);

            var response  = new Response(createdEmployee);
            var getParams = new { createdEmployee.Id };

            return(CreatedAtAction(nameof(Get), getParams, response));
        }
예제 #26
0
        public ActionResult EmployeeCreate(EmployeeCreateModel model)
        {
            if (ModelState.IsValid)
            {
                return(RedirectToAction("ViewRequests"));
            }

            return(View());
        }
        public async Task Create_When_There_Are_Notifications_Should_Return_BadRequest(
            EmployeeCreateModel employeeCreateModel,
            EmployeeController sut)
        {
            sut.NotificationStore.HasNotifications().Returns(true);

            var actual = await sut.Create(employeeCreateModel);

            actual.Should().BeOfType <BadRequestObjectResult>();
        }
        public ActionResult Create()
        {
            var model = new EmployeeCreateModel
            {
                TypeList      = GetEmployeeTypeList(),
                EducationList = GetEmployeeEducationList()
            };

            return(View(model));
        }
예제 #29
0
 public void Add(EmployeeCreateModel employeeModel, string email)
 {
     try
     {
         _employeeRepository.Add(employeeModel, email);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
예제 #30
0
        public IActionResult Post(int id, [FromBody] EmployeeCreateModel model)
        {
            var response = _commandBus.Execute <EmployeeUpdateCommand, EmployeeUpdateResponse>(new EmployeeUpdateCommand
            {
                Id        = id,
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Email     = model.Email
            });

            return(response.Succeeded ? Json("ok") : Json("error"));
        }