/// <summary>
 /// Create a new cg_SitePhotos object.
 /// </summary>
 /// <param name="sitePhotoId">Initial value of the SitePhotoId property.</param>
 public static cg_SitePhotos Createcg_SitePhotos(global::System.Int64 sitePhotoId)
 {
     cg_SitePhotos cg_SitePhotos = new cg_SitePhotos();
     cg_SitePhotos.SitePhotoId = sitePhotoId;
     return cg_SitePhotos;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the cg_SitePhotos EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTocg_SitePhotos(cg_SitePhotos cg_SitePhotos)
 {
     base.AddObject("cg_SitePhotos", cg_SitePhotos);
 }
        public ActionResult site_photo_new(FormCollection collection)
        {
            long parentId = Convert.ToInt64(collection["ParentId"]);
            string photoType = collection["PhotoType"];

            cg_SitePhotos newItem = new cg_SitePhotos();

            // Get file
            HttpPostedFileBase file = Request.Files["OriginalFileName"];
            string fileExtension = Path.GetExtension(file.FileName);

            // Add file info
            newItem.OriginalFileName = file.FileName;
            newItem.Description = collection["Description"];
            newItem.FileExtension = fileExtension;
            newItem.PhotoType = collection["PhotoType"];
            newItem.ParentId = parentId;
            newItem.FileSize = file.ContentLength;

            // Add object
            db.AddTocg_SitePhotos(newItem);
            db.SaveChanges();

            if (file.ContentLength > 0)
            {
                string filePath = Path.Combine(HttpContext.Server.MapPath("~/content/site-photos"), newItem.SitePhotoId + fileExtension);
                file.SaveAs(filePath);
            }

            // Redirect user
            return RedirectToAction("site_photos", new { parentId = parentId, photoType = photoType });
        }