public ActionResult Create(FormCollection collection)
        {
            var obj = new AdThuongNghiep();

            try
            {
                if (TryUpdateModel(obj))
                {
                    string tempFolder = "/Images/temp/" + Session["ID"] + "/";
                    string uploadFolder = "/Images/uploads/general/";

                    if (!Directory.Exists(Server.MapPath(uploadFolder)))
                    {
                        // Create the directory.
                        Directory.CreateDirectory(Server.MapPath(uploadFolder));
                    }
                    if (collection["HinhAnh"] != null)
                    {
                        HtmlHelperGeneral.MoveFile(Server.MapPath(tempFolder + collection["HinhAnh"]),
                                        Server.MapPath(uploadFolder + collection["HinhAnh"]));
                    }

                    obj.NgayTao = DateTime.Now;
                    obj.TrangThai = 0;
                    adRes.Add(obj);
                    adRes.Save();
                    TempData["message"] = "Thêm thành công";

                    return RedirectToAction("Details", new { id = obj.AdThuongNghiepID });

                }
                return View(obj);
            }
            catch (Exception ex)
            {
                TempData["error"] = ex;
                return RedirectToAction("Index");
            }
        }
Exemplo n.º 2
0
 public void Delete(AdThuongNghiep obj)
 {
     en.DeleteObject(obj);
 }
Exemplo n.º 3
0
 public void Add(AdThuongNghiep obj)
 {
     en.AddObject("AdThuongNghiep", obj);
 }