/// <summary> /// Create a new Package object. /// </summary> /// <param name="packageID">Initial value of the PackageID property.</param> public static Package CreatePackage(global::System.Int32 packageID) { Package package = new Package(); package.PackageID = packageID; return package; }
/// <summary> /// Deprecated Method for adding a new object to the Packages EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPackages(Package package) { base.AddObject("Packages", package); }
public ActionResult Edit(Package package, HttpPostedFileBase imgPackage) { if (ModelState.IsValid) { if (imgPackage != null) { string strPath = "~/Content/Uploads/Package/" + package.PackageID; if (!Directory.Exists(Server.MapPath(strPath))) { Directory.CreateDirectory(Server.MapPath(strPath)); } if (imgPackage != null && imgPackage.ContentLength > 0) { string filePath = Path.Combine(HttpContext.Server.MapPath(strPath), Path.GetFileName(package.PackageID + "_" + imgPackage.FileName)); if (!System.IO.File.Exists(filePath)) { imgPackage.SaveAs(filePath); package.Image = package.PackageID + "_" + imgPackage.FileName; } else { imgPackage.SaveAs(Path.Combine(HttpContext.Server.MapPath(strPath), Path.GetFileName(DateTime.Now.ToLongTimeString().Replace(":", "") + package.PackageID + "_" + imgPackage.FileName))); package.Image = DateTime.Now.ToLongTimeString().Replace(":", "") + package.PackageID + "_" + imgPackage.FileName; } } } db.Packages.Attach(package); db.ObjectStateManager.ChangeObjectState(package, EntityState.Modified); db.SaveChanges(); return RedirectToAction("Index"); } return View(package); }