Exemple #1
0
        public IActionResult Post([FromBody] Employee inputModel)
        {
            if (inputModel == null)
            {
                _logger.LogWarning(LoggingEvents.InputModelFormatIncorrect, "Incorrect format of input model");
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                _logger.LogWarning(LoggingEvents.InputModelFormatIncorrect, "Model state is not valid ");
                return(Unprocessable(ModelState));
            }
            _logger.LogInformation(LoggingEvents.AddEmployee, "Trying to add employee {Name}", inputModel.Name);
            _responseData = _mapper.ToEntity(_employeeService.AddEmployee(_mapper.ToDomainModel(inputModel)));
            _logger.LogInformation(LoggingEvents.AddEmployee, "Adding employee {Name} successful", inputModel.Name);

            if (_responseData.returnCode == APIErrorCode.Created)
            {
                return(CreatedAtRoute("GetEmployeeById", new { id = _responseData.Data.First().Id }, _responseData.Data.First()));
            }
            else
            {
                throw new ApplicationException("An exception occurred in one of the layers");
            }
        }
        //[Route("api/Employee/AddEmployee")]
        public IActionResult AddEmployee(Employee employee)
        {
            var emp       = _employeeService.AddEmployee(employee);
            var employeee = _mapper.Map <EmployeeDTO>(emp);

            return(Ok(employeee));
        }
Exemple #3
0
        // Added By Hojjat:
        public JsonResult Employee_Insert(AddEmployeeRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            #region Access Check

            bool hasPermission = GetEmployee().IsGuaranteed("Employee_Insert");
            if (!hasPermission)
            {
                response.ErrorMessages.Add("AccessDenied");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            #endregion

            try
            {
            }
            catch (Exception ex)
            {
                //response.success = false;
                response.ErrorMessages.Add("در آپلود کردن فایل خطایی به وجود آمده است.");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }

            request.Discontinued = false;

            response = _employeeService.AddEmployee(request, GetEmployee().ID);

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public async Task <IActionResult> Add(EmployeeViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Temporary solution.
                EmployeeDTO emp = new EmployeeDTO
                {
                    Currency           = "PLN",
                    EmailAddress       = model.EmailAddress,
                    EmploymentDate     = model.EmploymentDate,
                    FirstName          = model.FirstName,
                    IdentityCardNumber = model.IdentityCardNumber,
                    LastName           = model.LastName,
                    PESEL       = model.PESEL,
                    PhoneNumber = model.PhoneNumber,
                    Position    = model.Position.ToString(),
                    Salary      = model.Salary,
                    UserRole    = model.UserRole.ToString()
                };

                await _service.AddEmployee(emp);

                return(RedirectToAction("Index"));
            }

            // Something failed redisplay form.
            return(View());
        }
Exemple #5
0
        public int Execute(CreateEmployeeForm form)
        {
            if (!form.DepartmentId.HasValue)
            {
                throw new FormException("Отдел не выбран.");
            }

            var department = _departmentService.GetById(form.DepartmentId.Value);

            Employee employee = new Employee(
                form.FirstName,
                form.Surname,
                form.Patronymic,
                form.WorkplacePresenceRequired,
                form.PersonnelNumber,
                department);

            try
            {
                employee = _employeeService.AddEmployee(employee);
            }
            catch (EmployeeAlreadyExistsException e)
            {
                throw new FormException(e.Message);
            }

            department.AddEmployee(employee);

            return(employee.Id);
        }
Exemple #6
0
        public async Task AddEmployee_WhenSuppliedWithANewEmployeeObject_ShouldReturnTheObjectWithANewID()
        {
            Employee Source = new Employee()
            {
                name       = "Peter Parker",
                email      = "*****@*****.**",
                gender     = "Male",
                status     = "Active",
                created_at = DateTime.Now,
                updated_at = DateTime.Now
            };

            SaveEmployeeResponse response = new SaveEmployeeResponse()
            {
                data = new Employee()
                {
                    id = 1, name = "Peter Parker", email = "*****@*****.**", gender = "Male", status = "Active", created_at = DateTime.Now, updated_at = DateTime.Now
                },
                Success = true
            };

            restApiMock.Setup(x => x.AddEmployee(Source)).ReturnsAsync(response);

            var result = await employeeService.AddEmployee(Source);

            Assert.AreEqual(1, result.data.id);
            Assert.AreEqual(Source.name, result.data.name);
            Assert.AreEqual(Source.email, result.data.email);
            Assert.AreEqual(Source.gender, result.data.gender);
            Assert.AreEqual(Source.status, result.data.status);
            Assert.IsTrue(result.Success);
        }
        public async Task <ActionResult <Employee> > CreateEmployee(Employee employee)
        {
            try
            {
                if (employee == null)
                {
                    return(BadRequest());
                }

                var emp = await employeeService.GetEmployeeByEmail(employee.Email);

                if (emp != null)
                {
                    ModelState.AddModelError("email", "Employee email already in use");
                    return(BadRequest(ModelState));
                }

                var createdEmployee = await employeeService.AddEmployee(employee);

                return(CreatedAtAction(nameof(GetEmployee), new { id = createdEmployee.EmployeeId },
                                       createdEmployee));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error retrieving data from the database"));
            }
        }
Exemple #8
0
        public ActionResult AddEmployee(AddEmployeeDetails model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (_employeeService.EmployeeExist(model.BankId, model.EmployeeCode ?? 0))
            {
                ModelState.AddModelError("Employee", "The employee code is already in use.");
                return(View(model));
            }
            if (_userManager.DoseUserExist(model.Username))
            {
                ModelState.AddModelError("User", "The username is already taken.");
                return(View(model));
            }
            MembershipCreateStatus status;

            Membership.CreateUser(model.Username, model.Password, model.Email, model.Question, model.Answer, true, out status);
            if (!ModelState.IsValid || status != MembershipCreateStatus.Success)
            {
                return(View(model));
            }
            Roles.AddUserToRole(model.Username, "Banker");
            _employeeService.AddEmployee(model.BankId, new EmployeeBO
            {
                Code       = model.EmployeeCode ?? 0,
                GivenName  = model.GivenName,
                FamilyName = model.FamilyName,
                Phone      = model.Phone,
                Email      = model.Email,
                Username   = model.Username
            });
            return(RedirectToAction("EmployeeManager"));
        }
Exemple #9
0
        public async Task <ActionResult> Create(Employee employee)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _employeeService.AddEmployee(employee);

                    return(RedirectToAction("Index"));
                }

                return(View(employee));
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    int    index   = ex.InnerException.Message.IndexOf("UC_");
                    string message = ex.InnerException.Message;
                    if (index > 0)
                    {
                        message = message.Substring(0, index - 1);
                    }
                    ModelState.AddModelError("Error", "There was an error during: " + message);
                }
                else
                {
                    ModelState.AddModelError("Error", "There was an error during: " + ex.ToString());
                }

                return(View(employee));
            }
        }
Exemple #10
0
        public async Task <ActionResult> Post(Guid companyId, AddEmployeeRequest request)
        {
            await _employeeService.AddEmployee(companyId, request.FirstName, request.LastName, request.Phone,
                                               request.Email, request.IsContactEmployee);

            return(Ok());
        }
        public IActionResult OnPost()
        {
            try
            {
                var temp   = Employee;
                var errors = ModelState.Values.SelectMany(v => v.Errors);
                if (ModelState.IsValid)
                {
                    if (Employee.Id > 0)
                    {
                        Employee = _employeeService.UpdateEmployee(Employee);
                        CalculateCosts(Employee);
                        _employeeBenefitService.UpdateEmployeeBenefitsCost(Employee);
                    }

                    else
                    {
                        Employee = _employeeService.AddEmployee(Employee);
                        CalculateCosts(Employee);
                        _employeeBenefitService.AddEmployeeBenefitsCost(Employee);
                    }

                    return(RedirectToPage("Index"));
                }

                return(Page());
            }

            catch (ServiceException ex)
            {
                _logger.LogError("Error OnPost() Edit Employees Page. ErroCode: {0}, Message {1}", ex.ErrorCode, ex.ToString());
                throw ex;
            }
        }
Exemple #12
0
        public ActionResult Create(EmployeeViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(viewModel));
                }
                // Mapper.Initialize(cfg => cfg.CreateMap<CustomerDTO, CustomerViewModel>());
                //  var customer = Mapper.Map<CustomerDTO>(viewModel);
                // viewModel.NewVacancy.ToList().ForEach(x => customer.Vacancies.Add(vacancyService.))

                var employee = new EmployeeDTO
                {
                    EmployeeFirstName = viewModel.EmployeeFirstName,
                    EmployeeLastName  = viewModel.EmployeeLastName,
                    EmployeeAddress   = viewModel.EmployeeAddress,
                    Unemplyed         = true
                };

                employeeService.AddEmployee(employee);

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }
            return(View(viewModel));
        }
Exemple #13
0
        public IHttpActionResult Add(EmployeeViewModel emp)
        {
            try
            {
                if (emp != null)
                {
                    var emp_ID = _service.AddEmployee(emp);

                    if (emp_ID > 0)
                    {
                        return(Content(HttpStatusCode.Created, "New employee added successfully."));
                    }
                    else
                    {
                        return(Content(HttpStatusCode.InternalServerError, "No able save new employee. Please contact Admin."));
                    }
                }
                else
                {
                    return(Content(HttpStatusCode.BadRequest, "Employee data cannot be null"));
                }
            }
            catch (Exception ex)
            { return(InternalServerError(ex)); }
        }
        public HttpResponseMessage Post([FromBody] Employee employee)
        {
            if (employee == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Invalid Input. employee is null"));
            }

            try
            {
                int empId = _employeeService.AddEmployee(employee);

                if (empId != 0)
                {
                    employee.EmployeeId = empId;
                    var message = Request.CreateResponse(HttpStatusCode.Created, employee);
                    message.Headers.Location = new System.Uri($"{Request.RequestUri}/{ empId.ToString()}");
                    return(message);
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "Internal Server Exception"));
                }
            }
            catch (System.Exception exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "Internal Server Exception", exception));
            }
        }
 public IActionResult Add(Employee employee)
 {
     employee.Username = employee.Name;
     employee.Password = "******";
     employeeService.AddEmployee(employee);
     return(RedirectToAction(nameof(List)));
 }
        public async Task <IActionResult> Post([FromBody] EmployeeViewModel employee)
        {
            var employeeData    = ConvertEmployeeModelToEmployee(employee);
            var createdEmployee = await _employeeService.AddEmployee(employeeData);

            return(CreatedAtAction(nameof(Get), new { employeeId = createdEmployee.Id.ToString() }, createdEmployee));
        }
Exemple #17
0
 public IActionResult Add(Employee employee)
 {
     if (ModelState.IsValid)
     {
         _employeeService.AddEmployee(employee);
     }
     return(View());
 }
        public async Task <IServiceResponse <bool> > AddEmployee(EmployeeDTO employee)
        {
            return(await HandleApiOperationAsync(async() => {
                await _employeeSvc.AddEmployee(employee);

                return new ServiceResponse <bool>(true);
            }));
        }
Exemple #19
0
 public ActionResult Add(EmployeeModel employee)
 {
     if (employee != null)
     {
         employeeService.AddEmployee(employee);
     }
     return(RedirectToAction("Index"));
 }
        private void SaveExecute()
        {
            try
            {
                if (!ValidationClass.JMBGisValid(Employee.JMBG))
                {
                    MessageBox.Show("JMBG  nije validan.");
                    return;
                }

                //if (!ValidationClass.JMBGIsUnique(employee.JMBG))
                //{
                //    MessageBox.Show("JMBG  already exists in database");
                //    return;
                //}


                if (!ValidationClass.IsValidEmail(Employee.Email))
                {
                    MessageBox.Show("Email nije validan");
                    return;
                }

                int salary;
                if (!Int32.TryParse(Salary, out salary))
                {
                    MessageBox.Show("Plata mora biti broj");
                    return;
                }

                Employee.Salary      = salary;
                Employee.DateOfBirth = StartDate;



                //string textForFile = String.Format("Added user {0} {1} JMBG {2}", employee.FirstName,
                //              employee.LastName, employee.JMBG);
                //eventObject.OnActionPerformed(textForFile);
                //employee.GenderID = gender.GenderID;

                isUpdateUser = true;


                employeeService.AddEmployee(employee);

                employee = new tblEmployee();

                Salary = "";
                //MessageBox.Show("Uspesno ste dodali menadzera");

                addEmployee.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemple #21
0
 public async Task <ActionResult <EmployeeDTO> > AddEmployee(Employee employee)
 {
     try{
         return(new OkObjectResult(await _employeeService.AddEmployee(employee)));
     }
     catch {
         return(new StatusCodeResult(500));
     }
 }
Exemple #22
0
 public ActionResult Add(Employee model)
 {
     if (ModelState.IsValid)
     {
         _employeeService.AddEmployee(model);
         return(RedirectToAction("GetAll"));
     }
     return(View(model));
 }
        public async Task <IActionResult> AddEmployee(Employee employee)
        {
            employee.Id         = Guid.NewGuid();
            employee.InternalId = await _employeeService.GetNextValidIdForEmployee();

            var employeeId = await _employeeService.AddEmployee(employee);

            return(Json(employeeId));
        }
        public async Task <EmployeeResponseDto> EmployeeManagementInsert(EmployeeDto requestDto)
        {
            var result = await _employeeService.AddEmployee(requestDto).ConfigureAwait(false);

            return(new EmployeeResponseDto
            {
                StatusCode = result != default ? HttpStatusCode.OK : HttpStatusCode.Unauthorized,
                StatusDescription = result != default ? "Ok" : "Error",
            });
Exemple #25
0
        public JsonResult AddEmployee(Employee employee)
        {
            var result = _employeeService.AddEmployee(employee);

            return(Json(new
            {
                sucess = result
            }));
        }
 public HttpResponseMessage AddEmployee(Employee emp)
 {
     try {
         employeeService.AddEmployee(emp);
         return(Request.CreateResponse(HttpStatusCode.Created, emp));
     } catch (Exception ex) {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
        public async Task <IActionResult> AddEmployee(Employee value, CancellationToken ct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var empinfo = await _employeeService.AddEmployee(value, ct);

            return(Created("", empinfo));
        }
        public ActionResult <EmployeeModel> addEmployee(EmployeeModel employee)
        {
            var addedEmployee = service.AddEmployee(employee);

            if (addedEmployee == null)
            {
                return(NotFound());
            }
            return(addedEmployee);
        }
Exemple #29
0
        public ActionResult Create(Employee employee)
        {
            if (ModelState.IsValid)
            {
                _employeeService.AddEmployee(employee);
                return(RedirectToAction("Index"));
            }

            return(View(employee));
        }
        public async Task <ActionResult <Employee> > AddEmployee(Employee employee)
        {
            if (employee == null)
            {
                return(BadRequest());
            }
            await employeeService.AddEmployee(employee);

            return(Ok(employee));
        }