Ejemplo n.º 1
0
        public ActionResult Save(Staff staff)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new StaffFormViewModel()
                {
                    Staff       = staff,
                    Departments = _context.Departments.ToList()
                };

                return(View("StaffForm", viewModel));
            }

            if (staff.Id == 0)
            {
                _context.Staffs.Add(staff);
            }
            else
            {
                var staffInDb = _context.Staffs.Single(c => c.Id == staff.Id);
                staffInDb.Firstname    = staff.Firstname;
                staffInDb.Lastname     = staff.Lastname;
                staffInDb.DepartmentId = staff.DepartmentId;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Staffs"));
        }
Ejemplo n.º 2
0
        public ActionResult NewStaff()
        {
            var categoryRepo = _categoryStaffRepository.GetAll().ToList();
            var staffVM      = new StaffFormViewModel {
                Staff = new Staff(), Categories = categoryRepo
            };

            return(View("StaffForm", staffVM));
        }
Ejemplo n.º 3
0
        public ActionResult New()
        {
            var departments = _context.Departments.ToList();
            var viewModel   = new StaffFormViewModel
            {
                Staff       = new Staff(),
                Departments = departments
            };

            return(View("StaffForm", viewModel));
        }
Ejemplo n.º 4
0
        public ActionResult New()
        {
            var staffgrade = _context.StaffGrades.ToList();

            var viewModel = new StaffFormViewModel
            {
                Staff  = new Staff(),
                Grades = staffgrade
            };

            return(View("New", viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult StaffForm()
        {
            var addressTypes     = _context.AddressTypes.ToList();
            var phoneNumberTypes = _context.PhoneNumberTypes.ToList();
            var viewModel        = new StaffFormViewModel
            {
                Staff            = new Staff(),
                AddressTypes     = addressTypes,
                PhoneNumberTypes = phoneNumberTypes
            };

            return(View("StaffForm", viewModel));
        }
Ejemplo n.º 6
0
        public ActionResult Delete(int id)
        {
            var staff = _context.Staffs.SingleOrDefault(m => m.Id == id);

            if (staff == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new StaffFormViewModel
            {
                StaffId = id,
                Staff   = staff,
            };

            return(View(viewModel));
        }
Ejemplo n.º 7
0
        public ActionResult Edit(int id)
        {
            var staff = _context.Staffs.SingleOrDefault(c => c.Id == id);

            if (staff == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new StaffFormViewModel()
            {
                Staff       = staff,
                Departments = _context.Departments.ToList()
            };

            return(View("StaffForm", viewModel));
        }
Ejemplo n.º 8
0
        public ActionResult Edit(int id)
        {
            var staff = _context.Staffs.SingleOrDefault(s => s.StaffId == id);

            if (staff == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new StaffFormViewModel
            {
                Staff  = staff,
                Grades = _context.StaffGrades.ToList()
            };

            return(View("New", viewModel));
        }
Ejemplo n.º 9
0
        public ActionResult Edit(int id)
        {
            var allStaff = new StaffRepository().GetAll().ToList();

            var staff = _staffRepository.GetAll()
                        .ToList()
                        .SingleOrDefault(s => s.Id == id);

            if (staff == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new StaffFormViewModel {
                Staff = staff, Categories = _categoryStaffRepository.GetAll().ToList()
            };

            return(View("StaffForm", viewModel));
        }
Ejemplo n.º 10
0
        public ActionResult Edit(int id)
        {
            var staff = _context.Staffs.SingleOrDefault(c => c.Id == id);

            if (staff == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new StaffFormViewModel
            {
                Staff            = staff,
                AddressTypes     = _context.AddressTypes.ToList(),
                PhoneNumberTypes = _context.PhoneNumberTypes.ToList()
            };

            return(View("StaffForm", viewModel));
        }
Ejemplo n.º 11
0
        public ActionResult Save(Staff staff)
        {
            var staffRepo = new StaffRepository();

            if (!ModelState.IsValid)
            {
                var viewModel = new StaffFormViewModel {
                    Categories = new CategoryStaffRepository().GetAll().ToList()
                };

                return(View("StaffForm", viewModel));
            }
            if (staff.Id == 0)
            {
                _staffRepository.Create(staff);
            }
            else
            {
                _staffRepository.Update(staff);
            }
            return(RedirectToAction("Index", "Staff"));
        }
Ejemplo n.º 12
0
        public ActionResult Save(Staff staff)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new StaffFormViewModel
                {
                    Staff  = staff,
                    Grades = _context.StaffGrades.ToList()
                };

                return(View("New", viewModel));
            }

            if (staff.StaffId == 0)
            {
                _context.Staffs.Add(staff);
            }

            else
            {
                var StaffInDb = _context.Staffs.Single(s => s.StaffId == staff.StaffId);

                StaffInDb.StaffFirstName = staff.StaffFirstName;
                StaffInDb.StaffSurname   = staff.StaffSurname;
                StaffInDb.StaffGradeId   = staff.StaffGradeId;

                if (StaffInDb.PhoneNumber == 0)
                {
                    Random random = new Random();
                    int    number = random.Next(1, 99);

                    StaffInDb.PhoneNumber = number;
                }
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Staff"));
        }
Ejemplo n.º 13
0
        public ActionResult Save(Staff staff)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new StaffFormViewModel
                {
                    Staff            = staff,
                    AddressTypes     = _context.AddressTypes.ToList(),
                    PhoneNumberTypes = _context.PhoneNumberTypes.ToList()
                };
                return(View("StaffForm", viewModel));
            }
            if (staff.Id == 0)
            {
                _context.Staffs.Add(staff);
            }

            else
            {
                var staffInDb = _context.Staffs.Single(c => c.Id == staff.Id);
                staffInDb.FirstName                    = staff.FirstName;
                staffInDb.MiddleName                   = staff.MiddleName;
                staffInDb.LastName                     = staff.LastName;
                staffInDb.Email                        = staff.Email;
                staffInDb.HireDate                     = staff.HireDate;
                staffInDb.TerminationDate              = staff.TerminationDate;
                staffInDb.StreetAddress                = staff.StreetAddress;
                staffInDb.EmergencyContactName         = staff.EmergencyContactName;
                staffInDb.EmergencyContactAddress      = staff.EmergencyContactAddress;
                staffInDb.EmergencyContactPhone        = staff.EmergencyContactPhone;
                staffInDb.EmergencyContactRelationship = staff.EmergencyContactRelationship;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Staff"));
        }