public ActionResult Create(Staff_info staff) { if (ModelState.IsValid) { try { System.Collections.Specialized.NameValueCollection postedValues = Request.Form; staff.Create_date = System.DateTime.Now; staff.Join_date = System.DateTime.Now; staff.Address.City = postedValues["Address.City"]; staff.Address.Country = postedValues["Address.Country"]; staff.Address.House_number = postedValues["Address.House_number"]; staff.Address.Postcode = postedValues["Address.Postcode"]; staff.Address.Province = postedValues["Address.Province"]; staff.Address.Street_name = postedValues["Address.Street_name"]; staff.Address.Street_number = postedValues["Address.Street_number"]; repo.InsertStaffInfo(staff); repo.Save(); return RedirectToAction("Index"); } catch (Exception ex) { //get the innermost exception while (ex.InnerException != null) { ex = ex.InnerException; } ModelState.AddModelError("", "error on create: " + ex.GetBaseException().Message); } } return View(staff); }
public void UpdateStaffInfo(Staff_info staffInfo) { context.Entry(staffInfo).State = EntityState.Modified; }
public ActionResult Edit(Staff_info staff) { if (ModelState.IsValid) { try { System.Collections.Specialized.NameValueCollection postedValues = Request.Form; Address addre = new Address(); Staff_info oldStaff = (Staff_info)Session["staff"]; staff.Create_date = oldStaff.Create_date; staff.Address_id = oldStaff.Address_id; staff.Staff_id = oldStaff.Staff_id; staff.Address = oldStaff.Address; staff.Address.City = postedValues["Address.City"]; staff.Address.Country = postedValues["Address.Country"]; staff.Address.House_number = postedValues["Address.House_number"]; staff.Address.Postcode = postedValues["Address.Postcode"]; staff.Address.Province = postedValues["Address.Province"]; staff.Address.Street_name = postedValues["Address.Street_name"]; staff.Address.Street_number = postedValues["Address.Street_number"]; repo.UpdateAddress(staff.Address); repo.UpdateStaffInfo(staff); repo.Save(); return RedirectToAction("Index"); } catch (Exception ex) { //get the innermost exception while (ex.InnerException != null) { ex = ex.InnerException; } ModelState.AddModelError("", "error on create: " + ex.GetBaseException().Message); } } //ViewBag.Big_Image_id = new SelectList(db.Image_info, "Image_id", "Path", menu.Big_Image_id); //ViewBag.Small_Image_id = new SelectList(db.Image_info, "Image_id", "Path", menu.Small_Image_id); return View(staff); }
public void InsertStaffInfo(Staff_info staffInfo) { int id = context.Database.SqlQuery<int>("GetStaffInfoMaxID").Single() + 1; context.Staff_info.Add(staffInfo); }