コード例 #1
0
 public IActionResult Create(CreateEmployeeViewModel employee)
 {
     _service.Add(employee);
     return(RedirectToAction("Index"));
 }
コード例 #2
0
        public ActionResult Add(EmplyeeBindingModel emp)
        {
            //check if model is valid, if not -> redirect to Index with error message
            if (!ModelState.IsValid)
            {
                TempData["class"]    = "alert-danger";
                TempData["Response"] = "Unable to add new Employee ";
                return(RedirectToAction("Index"));
            }

            //Check if an entity with current name is existing
            if (_employee.All().Any(i => i.Name == emp.Name))
            {
                TempData["class"]    = "alert-danger";
                TempData["Response"] = "Bad Request! Unvalid Input Username should be unique!";
                return(RedirectToAction("Index"));
            }

            var employee = new Employee()
            {
                Name     = emp.Name,
                Position = emp.Position,
            };

            //check if business partner field is empty
            if (emp.BusinessPartner != null)
            {
                //take business partner from db by given name
                var empBusnessPartner = _businessPartner.All().FirstOrDefault(i => i.Name == emp.BusinessPartner);

                //check if exists
                if (empBusnessPartner == null)
                {
                    TempData["class"]    = "alert-danger";
                    TempData["Response"] = "Bad Request! That Business Partner does not exist ! Tip : Check your input twice";
                    return(RedirectToAction("Index"));
                }
                employee.BusinessPartner   = empBusnessPartner;
                employee.BusinessPartnerId = empBusnessPartner.Id;
            }
            //Check if supervisor field is empty
            if (emp.SupervisorName != null)
            {
                //Check if supervisor and Name is equal
                var supervisor = _employee.All().FirstOrDefault(i => i.Name == emp.SupervisorName);
                if (emp.SupervisorName == emp.Name)
                {
                    TempData["class"]    = "alert-danger";
                    TempData["Response"] = "Bad Request! You can not select the same Supervisor as the current user";
                    return(RedirectToAction("Index"));
                }
                //Check if supervisor is an existing employee
                if (supervisor == null)
                {
                    TempData["class"]    = "alert-danger";
                    TempData["Response"] = "Bad Request! Invalid Supervisor's name ! It should be an existing Employee";
                    return(RedirectToAction("Index"));
                }

                if (_employee.checkIfCanBeSupervisor(employee, supervisor))
                {
                    TempData["class"]    = "alert-danger";
                    TempData["Response"] = "Unable to add new Employee ";
                    return(RedirectToAction("Index"));
                }

                employee.Supervisor   = supervisor;
                employee.SupervisorId = supervisor.Id;
            }
            _employee.Add(employee);
            return(RedirectToRoute("Employee"));
        }
コード例 #3
0
 public async Task <IActionResult> AddEmployee([FromBody] AddEmployeeDto newEmployee)
 {
     return(Ok(await _employeeService.Add(newEmployee)));
 }
コード例 #4
0
 public async Task <bool> CreateEmployee(Employee model) => await _service.Add(model);
コード例 #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!Helper.ValidateTexBox(txtName))
            {
                return;
            }

            if (!Helper.ValidateTexBox(txtContact))
            {
                return;
            }

            switch (cmbCardType.Text)
            {
            case "Customer":

                Customer cust = new Customer();

                try
                {
                    //cust.CardID = int.Parse(cmbCardType.SelectedValue.ToString());
                    cust.ContactPerson = txtContact.Text;
                    //cust.SupplierNum = txtCardID.Text;
                    cust.PostalAddress = txtAddress.Text;
                    cust.CustomerSince = dtpSupplierSince.Value;
                    //cust.DesignationID = int.Parse(cmbDesignation.SelectedValue.ToString());
                    cust.LocationAdress = txtLocation.Text;
                    cust.EmailAddress   = txtEmail.Text.Trim();
                    cust.CustomerName   = txtName.Text.Trim();
                    cust.PhoneNumber1   = txtPhone1.Text.Trim();
                    cust.PhoneNumber2   = txtPhone2.Text.Trim();
                    cust.PhoneNumber3   = txtPhone3.Text.Trim();
                    cust.Salutation     = txtSalutation.Text;;
                    cust.City           = txtCity.Text.Trim();
                    cust.Website        = txtWebsite.Text.Trim();
                    cust.DateAdded      = DateTime.Now;

                    switch (GetEntityState)
                    {
                    case EntityState.New:
                        _customer.Add(cust);
                        Helper.ShowMessage("Customer " + OperationStatus.SUCCESS_ADD, "Success",
                                           MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;

                    case EntityState.Dirty:
                        cust.CustomerID = _customerID;
                        _customer.Update(cust, c => c.CustomerID == _customerID);
                        Helper.ShowMessage("Customer " + OperationStatus.SUCCESS_UPDATE, "Success",
                                           MessageBoxButtons.OK, MessageBoxIcon.Information);

                        ConfigureForm("Save");
                        break;
                    }

                    Helper.ClearForm(this);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "An error occurred", "ucCardInfo", "btnSave|Customer");
                    Helper.ShowMessage(OperationStatus.FAILURE + "\n" + ex.Message, "Error",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                break;

            case "Supplier":

                Supplier supplier = new Supplier();

                try
                {
                    //supplier.CardID = int.Parse(cmbCardType.SelectedValue.ToString());
                    supplier.ContactPerson = txtContact.Text;
                    //supplier.SupplierNum = txtCardID.Text;
                    supplier.PostalAddress = txtAddress.Text;
                    supplier.SupplierSince = dtpSupplierSince.Value;
                    //supplier.DesignationID = int.Parse(cmbDesignation.SelectedValue.ToString());
                    supplier.LocationAdress = txtLocation.Text;
                    supplier.Email          = txtEmail.Text.Trim();
                    supplier.Name           = txtName.Text.Trim();
                    supplier.PhoneNumber1   = txtPhone1.Text.Trim();
                    supplier.PhoneNumber2   = txtPhone2.Text.Trim();
                    supplier.PhoneNumber3   = txtPhone3.Text.Trim();
                    supplier.Salutation     = txtSalutation.Text;;
                    supplier.City           = txtCity.Text.Trim();
                    supplier.Website        = txtWebsite.Text.Trim();

                    switch (GetEntityState)
                    {
                    case EntityState.New:
                        _supplier.Add(supplier);
                        Helper.ShowMessage("Supplier " + OperationStatus.SUCCESS_ADD, "Success",
                                           MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;

                    case EntityState.Dirty:
                        supplier.SupplierID = _supplierID;
                        _supplier.Update(supplier, s => s.SupplierID == _supplierID);
                        Helper.ShowMessage(OperationStatus.SUCCESS_UPDATE, "Success",
                                           MessageBoxButtons.OK, MessageBoxIcon.Information);

                        ConfigureForm("Save");
                        break;
                    }

                    Helper.ClearForm(this);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "An error occurred", "ucCardInfo", "btnSave|Supplier");
                    Helper.ShowMessage(OperationStatus.FAILURE + "\n" + ex.Message, "Error",
                                       MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                break;

            case "Employee":

                Employee employee = new Employee();

                try
                {
                    //supplier.CardID = int.Parse(cmbCardType.SelectedValue.ToString());
                    employee.ContactPerson = txtContact.Text;
                    //supplier.SupplierNum = txtCardID.Text;
                    employee.OtherNames = txtOnames.Text;
                    employee.Sex        = cmbSex.Text;
                    employee.FisrtName  = txtName.Text;
                    //employee.LocationAdress = txtLocation.Text;
                    employee.Email        = txtEmail.Text.Trim();
                    employee.Address      = txtAddress.Text.Trim();
                    employee.PhoneNumber1 = txtPhone1.Text.Trim();
                    employee.PhoneNumber2 = txtPhone2.Text.Trim();
                    employee.PhoneNumber3 = txtPhone3.Text.Trim();
                    //employee.Salutation = txtSalutation.Text; ;
                    //employee.City = txtCity.Text.Trim();
                    employee.EmployeeSince = dtpSupplierSince.Value;

                    switch (GetEntityState)
                    {
                    case EntityState.New:
                        _employee.Add(employee);
                        Helper.ShowMessage("Employee " + OperationStatus.SUCCESS_ADD, "Success",
                                           MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;

                    case EntityState.Dirty:
                        employee.EmployeeID = _employeeID;
                        _employee.Update(employee, em => em.EmployeeID == _employeeID);
                        Helper.ShowMessage(OperationStatus.SUCCESS_UPDATE, "Success",
                                           MessageBoxButtons.OK, MessageBoxIcon.Information);

                        ConfigureForm("Save");
                        break;

                    default:
                        break;
                    }

                    Helper.ClearForm(this);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "An error occurred", "ucCardInfo", "btnSave|Employee");
                    Helper.ShowMessage(OperationStatus.FAILURE + "\n" + ex.Message, "Error",
                                       MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                break;

            case "Personal":
                break;
            }
        }
コード例 #6
0
        public async Task <Employee> Post([FromBody] Employee employee)
        {
            var res = await employeeContext.Add(employee);

            return(res != null ? employee : null);
        }
コード例 #7
0
ファイル: EmployeeController.cs プロジェクト: DnC275/OOP
        public int AddEmployee(string name, int directorId = -1)
        {
            ViewEmployeeModel employeeModel = new ViewEmployeeModel(name, directorId);

            return(service.Add(ConvertModelToBbl(employeeModel)));
        }
コード例 #8
0
ファイル: EmployeeController.cs プロジェクト: GlebGulin/Staff
 public IActionResult Post([FromBody] Employee model)
 {
     return(Ok(
                _service.Add(model)));
 }
コード例 #9
0
 public async Task <ActionResult> AddEmployee(EmployeeModel model)
 {
     return(Ok(await _employeeService.Add(model)));
 }