示例#1
0
 public static HebbraCoDbfModel.Staff buildModel(StaffDetailVM staff, HebbraCoDbfModel.Staff s)
 {
     s.businessUnitId = staff.businessUnitId;
     s.staffCode      = staff.staffCode;
     s.firstName      = staff.firstName;
     s.middleName     = staff.middleName;
     s.lastName       = staff.lastName;
     s.dob            = staff.dob;
     s.startDate      = staff.startDate;
     s.profile        = staff.profile;
     s.emailAddress   = staff.emailAddress;
     s.Active         = true;
     return(s);
 }
示例#2
0
        public static Models.StaffDetailVM buildViewModel(HebbraCoDbfModel.Staff thisStaff)
        {
            StaffDetailVM vm = new StaffDetailVM
            {
                businessUnitCode = thisStaff.BusinessUnit.businessUnitCode,
                staffCode        = thisStaff.staffCode,
                firstName        = thisStaff.firstName,
                middleName       = thisStaff.middleName,
                lastName         = thisStaff.lastName,
                dob          = thisStaff.dob,
                startDate    = thisStaff.startDate,
                profile      = thisStaff.profile,
                emailAddress = thisStaff.emailAddress
            };

            return(vm);
        }
示例#3
0
        public ActionResult Create([Bind(Include = "businessUnitId,staffCode,firstName,middleName,lastName,dob,startDate,profile,emailAddress")] Task1Start.Models.StaffDetailVM staffVM)
        {
            ViewBag.businessUnitId = new SelectList(db.BusinessUnits.Where(b => b.Active == true), "businessUnitId", "businessUnitCode"); // Returns a list of business codes that are active

            if (ModelState.IsValid)                                                                                                       // If validation checks pass...
            {
                if (db.Staffs.Count(s => s.staffCode.Equals(staffVM.staffCode, StringComparison.OrdinalIgnoreCase) && s.Active == true) > 0)
                {
                    ViewBag.Message = "The staff code is already in use!";
                    return(View(staffVM));
                }
                else
                {
                    var model = StaffDetailVM.buildModel(staffVM); // Passes the view model data and gets back a Staff model
                    model.Active = true;                           // Sets the active flag to true (it's not been soft deleted!)
                    db.Staffs.Add(model);                          // Inserts the data to the database as a new row
                    db.SaveChanges();                              // Saves the changes to the database
                    return(RedirectToAction("Index"));             // Redirects to the Staff list
                }
            }

            return(View(staffVM)); // Returns back to the creation form with the errors from validation
        }