public ActionResult Img(HttpPostedFileBase files1, HttpPostedFileBase files2) { using (DOANCHUYENNGANHEntities db = new DOANCHUYENNGANHEntities()) { int idUser = ((USER)Session["TaiKhoan"]).IDUSER; var agency = db.AGENCies.Where(x => x.IDUSER == idUser).FirstOrDefault(); if (files1 == null && files2 == null) { ViewBag.Error = "Vui lòng chọn ảnh"; } else { var fileName = Path.GetFileName(files1.FileName); var fileName2 = Path.GetFileName(files2.FileName); var path = Path.Combine(Server.MapPath("~/img/agency/"), fileName); var path1 = Path.Combine(Server.MapPath("~/img/agency/"), fileName2); if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { files1.SaveAs(path); files2.SaveAs(path1); IMGAGENCY img = new IMGAGENCY(); img.FILENAME = files1.FileName; agency.IMGAGENCies.Add(img); db.SaveChanges(); } } } return(RedirectToAction("Index")); }
public ActionResult Create(AGENCY agency) { using (DOANCHUYENNGANHEntities db = new DOANCHUYENNGANHEntities()) { var user = (USER)Session["TaiKhoan"]; ViewBag.IDCATE = db.CATEGORies.FirstOrDefault().IDCATE; agency.IDUSER = user.IDUSER; db.AGENCies.Add(agency); try { db.SaveChanges(); } catch (Exception ex) { } } return(RedirectToAction("Index", new { id = agency.IDAGENCY })); }
public ActionResult SignUp(FormCollection collection, USER users) { var name = collection["hoten"]; var user = collection["tendn"]; var password = collection["matkhau"]; if (String.IsNullOrEmpty(user) || String.IsNullOrEmpty(password) || String.IsNullOrEmpty(name)) { ViewBag.Error = "không được bỏ trống"; } else { users.FULLNAME = name; users.USERNAME = user; users.PASSWORD = password; users.IDROLE = 2; data.USERs.Add(users); data.SaveChanges(); return(RedirectToAction("Index", "Agency")); } return(SignUp()); }