public ActionResult SaveStaff(StaffManagementViewModel model) { ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities(); //string result = "Error Staff Info is not saved!"; var result = false; try { tblCompany comp = new tblCompany(); if (model.tblCompany.CompanyId > 0) { comp = db.tblCompanies.Where(a => a.CompanyId == model.tblCompany.CompanyId).FirstOrDefault(); } {
comp.DateJoin = model.tblCompany.DateJoin; comp.Department = model.tblCompany.Department; comp.JobTitle = model.tblCompany.JobTitle; if (model.tblCompany.CompanyId <= 0) db.tblCompanies.Add(comp); db.SaveChanges(); model.CompanyId = comp.CompanyId; } tblStaff staff = new tblStaff(); if (model.StaffId > 0) { staff = db.tblStaffs.Where(a => a.StaffId == model.StaffId).FirstOrDefault(); } staff.StaffNo = model.StaffNo; staff.Picture =Picture ; staff.FName = model.FName; staff.LName = model.LName; staff.BirthDate = model.BirthDate; staff.PhoneNo = model.PhoneNo; staff.Email = model.Email; staff.FirstName = model.FirstName; staff.LastName = model.LastName; staff.PhoneNumb = model.PhoneNumb; staff.CompanyId = model.CompanyId; if (model.StaffId <= 0) { db.tblStaffs.Add(staff); } db.SaveChanges(); result = true; } catch (Exception ex) { throw ex; }
return Json(result, JsonRequestBehavior.AllowGet); }