示例#1
0
        public IActionResult AddSector(SectorDto sector)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            var result = sectorService.AddSector(sector);

            if (!result)
            {
                return(BadRequest("Error saving Sector"));
            }

            //return CreatedAtRoute("GetProductById", new { id = obj.ID });
            return(StatusCode(201));
        }
        private void SaveExecute(object parameter)
        {
            try
            {
                tblSector sectorInDb = sectorService.GetSectorByName(Sector.SectorName);

                if (sectorInDb != null)
                {
                    string str1 = string.Format("Sector with this name exists\n" +
                                                "Enter another sector name");
                    MessageBox.Show(str1);
                    return;
                }

                sectorService.AddSector(Sector);
                string str = string.Format("You added new sector");
                MessageBox.Show(str);
                view.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#3
0
        private void SaveExecute()
        {
            try
            {
                if (!ValidationClass.JMBGisValid(employee.JMBG))
                {
                    MessageBox.Show("JMBG  is not valid.");
                    return;
                }



                if (!ValidationClass.RegisterNumberIsValid(employee.IDNumber))
                {
                    MessageBox.Show("Registration number  is not valid");
                    return;
                }

                if (!ValidationClass.TelfonNumberValid(employee.PhoneNumber))
                {
                    MessageBox.Show("Telefon number  is not valid. It must have 9 numbers");
                    return;
                }


                employee.DateOfBirth = StartDate;
                Employee.LocationID  = SelctedLocation.ID;

                if (SelectedMenager != null)
                {
                    employee.ManagerId = SelectedMenager.ID;
                }


                if (Gender.Equals("male"))
                {
                    employee.Gender = "M";
                }
                else if (Gender.Equals("female"))
                {
                    employee.Gender = "F";
                }
                else
                {
                    employee.Gender = "O";
                }


                tblSector sectorDB = sectorService.GetSectorByName(Sector);


                employeeService.EditEmployee(Employee);

                if (sectorDB == null)
                {
                    sectorDB            = new tblSector();
                    sectorDB.SectorName = Sector;
                    sectorDB            = sectorService.AddSector(sectorDB);

                    employeeService.EditSector(Employee.EmployeeID, sectorDB);
                }
                else
                {
                    //some comment
                    employeeService.EditSector(Employee.EmployeeID, sectorDB);
                }
                if (Employee.ManagerId != null)
                {
                    if (SelectedMenager != null)
                    {
                        employeeService.EditManager((int)Employee.EmployeeID, SelectedMenager.ID);
                    }
                    else
                    {
                        employeeService.EditManager((int)Employee.EmployeeID, 0);
                    }
                }



                string textForFile = String.Format("Updated user {0} {1} JMBG {2} to {3} {4} JMBG {5}", oldEmployee.FirstName,
                                                   oldEmployee.LastName, oldEmployee.JMBG, employee.FirstName, employee.LastName, employee.JMBG);
                eventObject.OnActionPerformed(textForFile);



                editEmployee.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#4
0
        private void SaveExecute()
        {
            try
            {
                if (!ValidationClass.JMBGisValid(employee.JMBG))
                {
                    MessageBox.Show("JMBG  is not valid.");
                    return;
                }

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

                if (!ValidationClass.RegisterNumberIsValid(employee.IDNumber))
                {
                    MessageBox.Show("Registration number  is not valid. It must have 9 numbers");
                    return;
                }
                if (!ValidationClass.RegNumberIsUnique(employee.IDNumber))
                {
                    MessageBox.Show("Registration number  already exists in database");
                    return;
                }
                if (!ValidationClass.TelfonNumberValid(employee.PhoneNumber))
                {
                    MessageBox.Show("Telephone number  is not valid. It must have 9 numbers");
                    return;
                }

                employee.LocationID  = SelctedLocation.ID;
                employee.DateOfBirth = StartDate;


                employee.ManagerId = SelectedMenager.ID;



                if (Gender.Equals("male"))
                {
                    employee.Gender = "M";
                }
                else if (Gender.Equals("female"))
                {
                    employee.Gender = "F";
                }
                else
                {
                    employee.Gender = "O";
                }


                tblSector sectorDB = sectorService.GetSectorByName(Sector);

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



                tblEmployee emplInDb = employeeService.AddEmployee(employee);

                if (sectorDB == null)
                {
                    sectorDB            = new tblSector();
                    sectorDB.SectorName = Sector;
                    sectorDB            = sectorService.AddSector(sectorDB);
                    //employee.SectorID = sectorDB.SectorID;
                    employeeService.EditSector(emplInDb.EmployeeID, sectorDB);
                }
                else
                {
                    employeeService.EditSector(emplInDb.EmployeeID, sectorDB);
                }
                employeeService.EditManager(emplInDb.EmployeeID, SelectedMenager.ID);

                addEmployee.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#5
0
        private void SaveExecute()
        {
            try
            {
                if (!ValidationClass.JMBGisValid(employee.JMBG))
                {
                    MessageBox.Show("JMBG  is not valid.");
                    return;
                }

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

                if (!ValidationClass.RegisterNumberIsValid(employee.RegistrationNumber))
                {
                    MessageBox.Show("Registration number  is not valid");
                    return;
                }
                if (!ValidationClass.RegNumberIsUniqueForEdit(employee.RegistrationNumber, employee))
                {
                    MessageBox.Show("Registration number  already exists in database");
                    return;
                }
                if (!ValidationClass.TelfonNumberValid(employee.TelefonNumber))
                {
                    MessageBox.Show("Telefon number  is not valid. It must have 9 numbers");
                    return;
                }
                employee.LocationID  = SelctedLocation.LocationID;
                employee.DateOfBirth = StartDate;
                if (String.IsNullOrEmpty(selectedMenager.Menager))
                {
                    vwMenager menagerDB = employeeService.GetMenagerByName(" ");
                    employee.MenagerID = menagerDB.EmployeeID;
                }
                else
                {
                    employee.MenagerID = selectedMenager.EmployeeID;
                }

                string genderForDB;

                if (Gender.Equals("male"))
                {
                    genderForDB = "M";
                }
                else if (Gender.Equals("female"))
                {
                    genderForDB = "F";
                }
                else
                {
                    genderForDB = "O";
                }

                tblGender gender   = genderService.GetGenderByName(genderForDB);
                tblSector sectorDB = sectorService.GetSectorByName(Sector);

                if (sectorDB == null)
                {
                    sectorDB            = new tblSector();
                    sectorDB.SectorName = Sector;
                    sectorDB            = sectorService.AddSector(sectorDB);
                    employee.SectorID   = sectorDB.SectorID;
                }
                else
                {
                    employee.SectorID = sectorDB.SectorID;
                }

                employee.GenderID = gender.GenderID;

                isUpdateUser = true;

                string textForFile = String.Format("Updated user {0} {1} JMBG {2} to {3} {4} JMBG {5}", oldEmployee.FirstName,
                                                   oldEmployee.LastName, oldEmployee.JMBG, employee.FirstName, employee.LastName, employee.JMBG);
                eventObject.OnActionPerformed(textForFile);


                employeeService.EditEmployee(employee);

                editEmployee.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }