public ActionResult UserBorrow(RecordDataViewModel getrecorddata) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { if (getrecorddata.EmpID != Session["EmpID"].ToString() || getrecorddata.EmpName != Session["EmpName"].ToString()) { ModelState.AddModelError("UseDay", "請使用本人ID、姓名借用"); return(View(getrecorddata)); } EmpData empdata = Data.EmpData.Where(x => x.EmpID == getrecorddata.EmpID).FirstOrDefault(); if (empdata.EmpState == "已借用")//防止重複借卡 { ModelState.AddModelError("UseDay", "尚有未歸還或已預約卡片,請先歸還"); return(View(getrecorddata)); } else { empdata.EmpState = "已預約"; RecordData recorddata = new RecordData() { RecordID = Data.RecordData.Count() + 1, EmpID = getrecorddata.EmpID, TimeLend = getrecorddata.TimeLend, UseDay = getrecorddata.UseDay, CardID = "0001", //預約時,預設卡號"0001"為預約卡 RecordDisable = "False", RecordState = "已預約", }; Data.RecordData.Add(recorddata); Data.SaveChanges(); return(RedirectToAction("UserRecord")); } } }
public ActionResult AdmEdit(RecordDataViewModel getrecorddata) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { CardData carddata = Data.CardData.Where(x => x.CardName == getrecorddata.CardName).FirstOrDefault(); //if (carddata.CardState =="已借出")//防止選到已借出的卡片 //{ //} //else { carddata.CardState = "已借出"; } EmpData empdata = Data.EmpData.Where(x => x.EmpID == getrecorddata.EmpID).FirstOrDefault(); empdata.EmpState = "已借用"; //RecordData 儲存 RecordData recorddata = Data.RecordData.Where(x => x.RecordID == getrecorddata.RecordID).FirstOrDefault(); recorddata.EmpID = getrecorddata.EmpID; recorddata.CardID = carddata.CardID; recorddata.TimeLend = getrecorddata.TimeLend; recorddata.UseDay = getrecorddata.UseDay; recorddata.RecordState = "未歸還"; Data.SaveChanges(); } return(RedirectToAction("AdmReturnIndex")); }
public ActionResult EmpCreate(EmpData empdata) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { empdata.EmpDisable = "False"; Data.EmpData.Add(empdata); Data.SaveChanges(); } return(RedirectToAction("EmployeeIndex")); }
public ActionResult CardCreate(CardData createdata) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { createdata.CardDisable = "False"; Data.CardData.Add(createdata); Data.SaveChanges(); } return(RedirectToAction("CardIndex")); }
// 使用者續借 public ActionResult UserRenew(int recordid) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { var recdata = (from x in Data.RecordData where x.RecordID == recordid select x).FirstOrDefault(); recdata.UseDay = recdata.UseDay + 5; Data.SaveChanges(); return(RedirectToAction("UserRecord")); } }
public ActionResult UserEdit(RecordDataViewModel editdata) { using (EasyCardEntities4 data = new EasyCardEntities4()) { if (ModelState.IsValid) { RecordData recdata = data.RecordData.Where(x => x.RecordID == editdata.RecordID).FirstOrDefault(); recdata.TimeLend = editdata.TimeLend; recdata.UseDay = editdata.UseDay; data.SaveChanges(); } return(RedirectToAction("UserRecord")); } }
public ActionResult CardEdit(CardData getdata) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { if (ModelState.IsValid) { CardData carddata = Data.CardData.Where(x => x.CardID == getdata.CardID).FirstOrDefault(); carddata.CardID = getdata.CardID; carddata.CardDept = getdata.CardDept; carddata.CardName = getdata.CardName; carddata.CardState = getdata.CardState; carddata.CardAmount = getdata.CardAmount; Data.SaveChanges(); } return(RedirectToAction("CardIndex")); } }
// GET: Employee/Delete/5 public ActionResult EmpDelete(string empid) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { var empddata = (from x in Data.EmpData where x.EmpID == empid select x).FirstOrDefault(); if (empddata == null) { return(HttpNotFound()); } else { empddata.EmpDisable = "True"; Data.SaveChanges(); } return(RedirectToAction("EmployeeIndex")); } }
public ActionResult EmpEdit(EmpData getempdata) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { if (ModelState.IsValid) { EmpData empdata = Data.EmpData.Where(x => x.EmpID == getempdata.EmpID).FirstOrDefault(); empdata.EmpID = getempdata.EmpID; empdata.EmpCardCode = getempdata.EmpCardCode; empdata.EmpDept = getempdata.EmpDept; empdata.EmpName = getempdata.EmpName; empdata.Email = getempdata.Email; empdata.EmpState = getempdata.EmpState; empdata.Role = getempdata.Role; Data.SaveChanges(); } return(RedirectToAction("EmployeeIndex")); } }
// 使用者取消預約 public ActionResult UserDelete(int recordid) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { var recdata = (from x in Data.RecordData where x.RecordID == recordid select x).FirstOrDefault(); if (recdata == null) { return(HttpNotFound()); } else { recdata.RecordDisable = "True"; Data.SaveChanges(); } return(RedirectToAction("UserRecord")); } }
// GET: Card/Delete/5 //[AcceptVerbs(HttpVerbs.Delete)] //有別於get post public ActionResult CardDelete(string cardid) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { var carddata = (from x in Data.CardData where x.CardID == cardid select x).FirstOrDefault(); if (carddata == null) { return(HttpNotFound()); } else { carddata.CardDisable = "True"; Data.SaveChanges(); } return(RedirectToAction("CardIndex")); } }
public ActionResult AdmBorrow(RecordDataViewModel getrecorddata) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { CardData carddata = Data.CardData.Where(x => x.CardName == getrecorddata.CardName).FirstOrDefault(); //if (carddata.CardState == "已借出")//防止選到已借出的卡片 //{ //} //else { carddata.CardState = "已借出"; getrecorddata.CardID = carddata.CardID; } EmpData empdata = Data.EmpData.Where(x => x.EmpID == getrecorddata.EmpID).FirstOrDefault(); //if (empdata.EmpState == "已借用")//防止重複借卡 //{ //} //else { empdata.EmpState = "已借用"; } RecordData recorddata = new RecordData() { RecordID = Data.RecordData.Count() + 1, EmpID = getrecorddata.EmpID, CardID = getrecorddata.CardID, TimeLend = getrecorddata.TimeLend, UseDay = getrecorddata.UseDay, RecordDisable = "False", RecordState = "未歸還", }; Data.RecordData.Add(recorddata); Data.SaveChanges(); } return(RedirectToAction("AdmReturnIndex")); }
// 歸還確認 public ActionResult AdmReturnConfirm(RecordDataViewModel getrecorddata) { using (EasyCardEntities4 Data = new EasyCardEntities4()) { CardData carddata = Data.CardData.Where(x => x.CardName == getrecorddata.CardName).FirstOrDefault(); carddata.CardState = "可使用"; carddata.CardAmount = getrecorddata.CardAmount; EmpData empdata = Data.EmpData.Where(x => x.EmpID == getrecorddata.EmpID).FirstOrDefault(); empdata.EmpState = "可借用"; //RecordData 儲存 RecordData recorddata = Data.RecordData.Where(x => x.RecordID == getrecorddata.RecordID).FirstOrDefault(); recorddata.EmpID = getrecorddata.EmpID; recorddata.CardID = carddata.CardID; recorddata.TimeLend = getrecorddata.TimeLend; recorddata.UseDay = getrecorddata.UseDay; recorddata.TimeReturn = DateTime.Now; recorddata.RecordState = "已歸還"; Data.SaveChanges(); return(RedirectToAction("AdmReturnIndex")); } }