public ActionResult Create(Show show) { if (ModelState.IsValid) { try { show.Time = Convert.ToString(show.ATime).Substring(10, 6); var Tempdate = td.ThaiDate(show.Mydate); show.Date = Tempdate; if (show.pic != null) { byte[] Temp = new byte[show.pic.ContentLength]; show.pic.InputStream.Read(Temp, 0, show.pic.ContentLength); show.Picture = Temp; } db.Show.Add(show); db.SaveChanges(); } catch (Exception) { } } ViewBag.IDBand = new SelectList(db.Band, "IDBand", "NameBand"); ViewBag.IDPlace = new SelectList(db.Place, "IDPlace", "NamePlace"); return(RedirectToAction(nameof(Index))); }
public ActionResult Create(T_Requisition data) { ConvertDate convertD = new ConvertDate(); var data1 = _db.Teacher.ToList(); var dateNow = convertD.ThaiDate(data.Re_DateRequi); data.Re_DateRequi = Convert.ToDateTime(dateNow); var value = new List <TmpTeacher>(); foreach (var item in data1) { value.Add(new TmpTeacher { IDT = item.TeaId, NAMEFULL = item.Title.TName + " " + item.TeaName }); } ViewBag.Re_TeaId = new SelectList(value, "IDT", "NAMEFULL"); if (Convert.ToInt32(data.RequisitionID) < 0) { ModelState.AddModelError("RequisitionID", "กรุณาตรวจสอบ กรุณากรอกอีกครั้ง"); return(View(data)); } var Chk = _db.T_Requisition.Where(x => x.RequisitionID == data.RequisitionID).ToList(); if (ModelState.IsValid) { try { var p = int.TryParse(data.RequisitionID, out _); if (p) { var Year = DateTime.Now.ToString("yy"); data.RequisitionID = data.RequisitionID + "/" + Year; if (Chk.Count == 0) { data.Re_StepID = "0"; _db.T_Requisition.Add(data); _db.SaveChanges(); Session["Result"] = "okC"; Session["RequisitionID"] = data.RequisitionID; return(RedirectToAction("Waiting", "Requisition")); } else { ViewBag.Re_TeaId = new SelectList(value, "IDT", "NAMEFULL"); ModelState.AddModelError("RequisitionID", "เลขใบเบิกซ้ำ"); return(View(data)); } } else { ModelState.AddModelError("RequisitionID", "กรุณากรอกเลขที่ใบเบิกเป็นตัวเลข"); return(View(data)); } } catch { ModelState.AddModelError("RequisitionID", "เลขใบเบิกซ้ำ"); return(View(data)); } } else { return(View(data)); } }