public ActionResult AddHost() { AddHostModal s = new AddHostModal(); s.firm_list = new SelectList(context.getAllFirm(), "firm_id", "firm_name"); ViewData.Model = s; return View(); }
public ActionResult AddHost(AddHostModal host) { try { // TODO: Add insert logic here host.password = host.id_card.Substring(host.id_card.Length - 7); context.addEmpolyee(host.password, host.firm_id, host.name, host.id_card, host.birthday, host.gender, host.telephone, host.address); int? employee_id = context.getEmpolyeeIdByIdCard(host.id_card); context.addHost(employee_id, host.photo); return RedirectToAction("HostList"); } catch (Exception e) { ViewData["errorMessage"] = "Error"; return View(); } }
public ActionResult AddHost(int id, AddHostModal host) { if (Session["Identity"] == null) { return RedirectToAction("login"); } try { if (context.isHost(id) == 1) throw new Exception(); StringBuilder info = new StringBuilder(); String bas = ""; foreach (string file in Request.Files) { HttpPostedFileBase postFile = Request.Files[file]; if (postFile.ContentLength == 0) continue; string newFilePath = Server.MapPath("/Content/HostPhoto/host"); postFile.SaveAs(newFilePath + id); bas = "/Content/HostPhoto/host" + id; info.AppendFormat("Upload File: {0}/r/n", postFile.FileName); } ViewData["Info"] = info; // TODO: Add insert logic here //host.password = host.id_card.Substring(host.id_card.Length - 7); //context.addEmpolyee(host.password, host.firm_id, host.name, host.id_card, host.birthday, host.gender, host.telephone, host.address, ref id); //int? employee_id = context.getEmpolyeeIdByIdCard(host.id_card); context.addHost(id, bas); Session["errorMsg"] = "Success"; return RedirectToAction("HostList"); } catch (Exception e) { Session["errorMsg"] = "Ilegal"; return RedirectToAction("HostList"); } }
public ActionResult AddHost(int id) { if (Session["Identity"] == null) { return RedirectToAction("login"); } int? employee_id = id; getEmpolyeeByIdResult idr = context.getEmpolyeeById(employee_id).First(); AddHostModal s = new AddHostModal() { address = idr.empolyee_address, birthday = idr.birthday, firm_id = idr.firm_id, firm_list = new SelectList(context.getAllFirm(), "firm_id", "firm_name"), gender = idr.gender, id_card = idr.id_card, name = idr.name, telephone = idr.telephone }; ViewData.Model = s; return View(); }