예제 #1
0
        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);
        }
예제 #2
0
 public void UpdateStaffInfo(Staff_info staffInfo)
 {
     context.Entry(staffInfo).State = EntityState.Modified;
 }
예제 #3
0
        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);
        }
예제 #4
0
 public void InsertStaffInfo(Staff_info staffInfo)
 {
     int id = context.Database.SqlQuery<int>("GetStaffInfoMaxID").Single() + 1;
     context.Staff_info.Add(staffInfo);
 }