Exemplo n.º 1
0
        public async Task <IActionResult> Create(EmployeeAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var employee = Employee.Create(viewModel.Item.Name,
                                               viewModel.Item.BirthDate,
                                               viewModel.Item.TIN,
                                               viewModel.Item.EmployeeTypeId);
                var result = await _addEmployeeUseCase.Execute(employee);

                if (result.Status.Equals(CommandStatus.Success))
                {
                    return(Ok());
                }
                else
                {
                    viewModel.ErrorMessage = result.ErrorMessage;
                    return(StatusCode(400));
                }
            }
            else
            {
                return(StatusCode(400));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(EmployeeAddViewModel e)
        {
            try
            {
                if (e != null)
                {
                    var obj = m.EmployeeAdd(e);
                    if (obj != null)
                    {
                        return(RedirectToAction("Details/" + obj.EmployeeId));
                    }
                }
                else
                {
                    return(HttpNotFound());
                }
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <IActionResult> Create(EmployeeAddViewModel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                List <Department> allDepartments = await GetAllDepartments();

                viewmodel.AllDepartments = allDepartments;
                return(View(viewmodel));
            }

            Employee employee = viewmodel.Employee;

            using (IDbConnection conn = Connection)
            {
                string sql = $@"
                INSERT INTO Employee (
                    FirstName,
                    LastName,
                    IsSupervisor,
                    DepartmentId)
                VALUES (
                    '{employee.FirstName}',
                    '{employee.LastName}',
                    {(employee.IsSupervisor ? 1 : 0)},
                    {employee.DepartmentId});";

                await conn.ExecuteAsync(sql);

                return(RedirectToAction(nameof(Index)));
            }
        }
Exemplo n.º 4
0
        //Add New,HTTP Get Method
        public ActionResult Create()
        {
            //Create new object
            var emp = new EmployeeAddViewModel();

            return(View(emp));
        }
Exemplo n.º 5
0
        public IActionResult Add()
        {
            List <SelectListItem> cities = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Ankara", Value = "6"
                },
                new SelectListItem {
                    Text = "Antalya", Value = "7"
                },
                new SelectListItem {
                    Text = "İstanbul", Value = "34"
                },
                new SelectListItem {
                    Text = "Konya", Value = "42"
                }
            };

            var model = new EmployeeAddViewModel
            {
                Employee = new Employee(),
                Cities   = cities
            };

            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult Create(EmployeeAddViewModel newItem)
        {
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }
            try
            {
                var addedItem = m.EmployeeAdd(newItem);

                if (addedItem == null)
                {
                    return(View(newItem));
                }
                else
                {
                    return(RedirectToAction("Details", new { id = addedItem.EmployeeId }));
                }

                // TODO: Add insert logic here
            }
            catch
            {
                return(View(newItem));
            }
        }
Exemplo n.º 7
0
        public ActionResult Create(EmployeeAddViewModel newItem)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

            try
            {
                // Process the input
                var addedItem = m.EmployeeAdd(newItem);

                // If the item was not added, return the user to the Create page
                // otherwise redirect them to the Details page.
                if (addedItem == null)
                {
                    return(View(newItem));
                }
                else
                {
                    return(RedirectToAction("Details", new { id = addedItem.EmployeeId }));
                }
            }
            catch
            {
                return(View(newItem));
            }
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,DateOfBirth,Email")] EmployeeAddViewModel employee)
        {
            if (!ModelState.IsValid)
            {
                return(View(employee));
            }

            var employeeToAdd = new Employee()
            {
                UserName           = employee.Email,
                NormalizedUserName = employee.Email.ToUpper(),
                SecurityStamp      = Guid.NewGuid().ToString(),
                FirstName          = employee.FirstName,
                LastName           = employee.LastName,
                DateOfBirth        = employee.DateOfBirth,
                Email           = employee.Email,
                NormalizedEmail = employee.Email.ToUpper()
            };

            var createUser = await _userManager.CreateAsync(employeeToAdd, "P4$sw0rd").ConfigureAwait(false);

            if (!createUser.Succeeded)
            {
                return(RedirectToAction(nameof(Index)));
            }

            await _userManager.AddToRoleAsync(employeeToAdd, "employee").ConfigureAwait(false);

            return(RedirectToAction(nameof(Index)));
        }
        private ActionResult AddSingleTrainingProgram(EmployeeAddViewModel employee, int trainingProgramId)
        {
            try
            {
                using (SqlConnection conn = Connection)
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = @"INSERT INTO EmployeeTraining (EmployeeId, TrainingProgramId)
                                            OUTPUT INSERTED.Id
                                            VALUES (@employeeId, @trainingProgramId)";


                        cmd.Parameters.Add(new SqlParameter("@employeeId", employee.Id));
                        cmd.Parameters.Add(new SqlParameter("@trainingProgramId", trainingProgramId));

                        var id = (int)cmd.ExecuteScalar();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Exemplo n.º 10
0
        public ActionResult Create(EmployeeAddViewModel newEmployee)
        {
            //Validate incoming data
            if (!ModelState.IsValid)
            {
                return(View(newEmployee));
            }

            try
            {
                var addEmp = mc.EmployeeAddNew(newEmployee);
                if (addEmp == null)
                {
                    return(View(newEmployee));
                }
                else
                {
                    //Returns view
                    return(RedirectToAction("Details", new { id = addEmp.EmployeeId }));
                }
            }
            catch
            {
                return(View(newEmployee));
            }
        }
        public ActionResult Create(EmployeeAddViewModel newItem)
        {
            // Validate the input
            if (!ModelState.IsValid)
            {
                return(View(newItem));
            }

            try
            {
                // Process the input
                var addedItem = m.EmployeeAddNew(newItem);

                // If the item was not added, return the user to the Create page
                // otherwise redirect them to the Details page.
                if (addedItem == null)
                {
                    return(View(newItem));
                }
                else
                {
                    //if successful, redirect to the Details View
                    return(RedirectToAction("Details", new { id = addedItem.EmployeeId }));
                }
                //The returned object will have the unique identifier that was assigned
            }
            catch
            {
                return(View(newItem));
            }
        }
Exemplo n.º 12
0
        // ProductAdd()
        public EmployeeBaseViewModel EmployeeAdd(EmployeeAddViewModel e)
        {
            var obj = ds.Employees.Add(Mapper.Map <EmployeeAddViewModel, Employee>(e));

            ds.SaveChanges();
            return((obj == null) ? null : Mapper.Map <Employee, EmployeeBaseViewModel>(obj));
        }
Exemplo n.º 13
0
        // ProductAdd()
        public EmployeeBaseViewModel EmployeeAdd(EmployeeAddViewModel newEmployee)
        {
            var addedItem = ds.Employees.Add(mapper.Map <EmployeeAddViewModel, Employee>(newEmployee));

            ds.SaveChanges();

            return(addedItem == null ? null : mapper.Map <Employee, EmployeeBaseViewModel>(addedItem));
        }
Exemplo n.º 14
0
        // GET: Employee/Create
        public ActionResult Create()
        {
            //obj created based on "add" view model
            var obj = new EmployeeAddViewModel();

            //object passed to view
            return(View(obj));
        }
Exemplo n.º 15
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var employeeAddViewModel = new EmployeeAddViewModel();
            var db = this.employeeDbContext;

            employeeAddViewModel.EmployeesList = db.Employees.ToList();

            return(View(employeeAddViewModel));
        }
Exemplo n.º 16
0
        public IActionResult Index(EmployeeAddViewModel employeeAddViewModel)
        {
            var db = this.employeeDbContext;

            db.Employees.Add(employeeAddViewModel.NewEmployee);
            db.SaveChanges();
            //Redirect to get Index GET method
            return(RedirectToAction("Index"));
        }
Exemplo n.º 17
0
        // ProductAdd()

        public EmployeeBaseViewModel EmployeeAdd(EmployeeAddViewModel newEmployee)
        {
            //add new object                //map function , source        , destination, data
            var addnewItem = ds.Employees.Add(mapper.Map <EmployeeAddViewModel, Employee>(newEmployee));

            ds.SaveChanges();
            //returm mew object
            return(addnewItem == null ? null : mapper.Map <Employee, EmployeeBaseViewModel>(addnewItem));
        }
Exemplo n.º 18
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            EmployeeAddViewModel employeeAddViewModel = new EmployeeAddViewModel();

            using (var db = new EmployeeDbContext())
            {
                employeeAddViewModel.EmployeesList = db.Employees.ToList();
            }
            return(View(employeeAddViewModel));
        }
Exemplo n.º 19
0
        //Method  3: Add New
        public EmployeeBaseViewModel EmployeeAddNew(EmployeeAddViewModel newEmployee)
        {
            //Try to add new employee to database
            var addEmployee = ds.Employees.Add(mapper.Map <EmployeeAddViewModel, Employee>(newEmployee));

            //Saves changes in database
            ds.SaveChanges();

            //If successful returns mapped object, otherwise null
            return(addEmployee == null ? null : mapper.Map <Employee, EmployeeBaseViewModel>(addEmployee));
        }
        // GET: Employee/Create
        /*Create makes a list of All the Departments and puts that list of Departments into the ViewModel to be used.*/
        public async Task <IActionResult> Create()
        {
            List <Department> allDepartments = await GetAllDepartments();

            EmployeeAddViewModel viewmodel = new EmployeeAddViewModel
            {
                AllDepartments = allDepartments
            };

            return(View(viewmodel));
        }
Exemplo n.º 21
0
        public EmployeeBaseViewModel EmployeeAdd(EmployeeAddViewModel newEmployee)
        {
            // Attempt to add the new item.
            // Notice how we map the incoming data to the Employee design model class.
            var addedItem = ds.Employees.Add(mapper.Map <EmployeeAddViewModel, Employee>(newEmployee));

            ds.SaveChanges();

            // If successful, return the added item (mapped to a view model class).
            return(addedItem == null ? null : mapper.Map <Employee, EmployeeBaseViewModel>(addedItem));
        }
Exemplo n.º 22
0
        //The Index action method corresponding to the GET action
        //method will be called when you access the URL
        //(http://localhost/Employee/Index) or when you run the
        //application.

        //GET : /<controller>/
        public IActionResult Index()
        {
            //we are creating the ViewModel object and passing it to the view
            EmployeeAddViewModel employeeAddViewModel = new EmployeeAddViewModel();
            var db = this.employeeDbContext;

            employeeAddViewModel.EmployeesList = db.Employees.ToList();
            //employeeAddViewModel.NewEmployee = new Employee();

            return(View(employeeAddViewModel));
        }
        // GET: Employees/Create
        public ActionResult Create()
        {
            var departmentOptions = GetDepartmentOptions();
            var computerOptions   = GetAvailableComputers();
            var viewModel         = new EmployeeAddViewModel()
            {
                DepartmentOptions = departmentOptions,
                ComputerOptions   = computerOptions
            };

            return(View(viewModel));
        }
 public ActionResult Add(EmployeeAddViewModel model)
 {
     _employeeService.Create(new Employee
     {
         EmployeeName    = model.EmployeeName,
         EmployeeSurname = model.EmployeeSurname,
         DepartmentId    = model.DepartmentId,
         Picture         = model.Picture,
         State           = true
     });
     return(RedirectToAction("Index"));
 }
Exemplo n.º 25
0
        public EmployeeBaseViewModel EmployeeAddNew(EmployeeAddViewModel newEmp)
        {
            var addedItem = ds.Employees.Add(mapper.Map <EmployeeAddViewModel, Employee>(newEmp));

            //Add() anticipates an object of type Employee added to the data store
            ds.SaveChanges();
            //upon adding, save changes to the data store


            // If successful, return the added item (mapped to a view model class).
            return(addedItem == null ? null : mapper.Map <Employee, EmployeeBaseViewModel>(addedItem));
        }
 public ActionResult AssignTrainingPrograms(EmployeeAddViewModel employee)
 {
     employee.EmployeeTrainings = GetEmployeeTrainings(employee.Id);
     foreach (var id in employee.TrainingProgramIds)
     {
         if (!employee.EmployeeTrainings.Any(et => et.TrainingProgramId == id))
         {
             AddSingleTrainingProgram(employee, id);
         }
     }
     return(RedirectToAction("Details", new { employee.Id }));
 }
Exemplo n.º 27
0
        public async Task <IActionResult> Create()
        {
            var model         = new EmployeeAddViewModel();
            var employeeTypes = await _getEmployeeTypesUseCase.Execute();

            model.EmployeeTypeList = GenerateEmployeeTypeList(employeeTypes);
            model.Item             = new EmployeeViewModel();
            model.Item.Id          = 0;
            model.Item.BirthDate   = DateTime.Now;

            return(View(model));
        }
        private EmployeeAddViewModel GetEmployeeById(int id)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT e.Id, e.FirstName, e.LastName, e.DepartmentId, e.ComputerId, e.IsSupervisor, t.Id trainingProgramId, t.Name TrainingProgram, t.StartDate, t.EndDate 
                                    FROM Employee e 
                                    LEFT JOIN EmployeeTraining et
                                    ON et.EmployeeId = e.Id
                                    LEFT JOIN TrainingProgram t
                                    ON et.TrainingProgramId = t.Id
                                    WHERE e.Id = @id";

                    cmd.Parameters.Add(new SqlParameter("@id", id));

                    var reader = cmd.ExecuteReader();
                    EmployeeAddViewModel employee = null;

                    while (reader.Read())
                    {
                        if (employee == null)
                        {
                            employee = new EmployeeAddViewModel
                            {
                                Id               = reader.GetInt32(reader.GetOrdinal("Id")),
                                FirstName        = reader.GetString(reader.GetOrdinal("FirstName")),
                                LastName         = reader.GetString(reader.GetOrdinal("LastName")),
                                DepartmentId     = reader.GetInt32(reader.GetOrdinal("DepartmentId")),
                                ComputerId       = reader.GetInt32(reader.GetOrdinal("ComputerId")),
                                TrainingPrograms = new List <TrainingProgram>()
                            };
                        }
                        if (!reader.IsDBNull(reader.GetOrdinal("trainingProgramId")))
                        {
                            employee.TrainingPrograms.Add(new TrainingProgram()
                            {
                                Id        = reader.GetInt32(reader.GetOrdinal("trainingProgramId")),
                                Name      = reader.GetString(reader.GetOrdinal("TrainingProgram")),
                                StartDate = reader.GetDateTime(reader.GetOrdinal("StartDate")),
                                EndDate   = reader.GetDateTime(reader.GetOrdinal("EndDate"))
                            });
                        }
                    }
                    reader.Close();
                    return(employee);
                }
            }
        }
Exemplo n.º 29
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var employeeAddViewModel = new EmployeeAddViewModel();
            var db = this.employeeDbContext;

            employeeAddViewModel.EmployeesList = db.Employees.ToList();
            employeeAddViewModel.NewEmployee   = new Employee();
            if (Request.Headers["accept"].Any(x => x == "application/json"))
            {
                return(Ok(employeeAddViewModel));
            }

            return(View(employeeAddViewModel));
        }
        // GET: Employees/Edit/5
        public ActionResult Edit(int id)
        {
            var employee          = GetEmployeeById(id);
            var departmentOptions = GetDepartmentOptions();
            var computerOptions   = GetUsersComputerOrAvailable(id);
            var viewModel         = new EmployeeAddViewModel()
            {
                DepartmentId      = employee.DepartmentId,
                ComputerId        = employee.ComputerId,
                LastName          = employee.LastName,
                DepartmentOptions = departmentOptions,
                ComputerOptions   = computerOptions
            };

            return(View(viewModel));
        }