コード例 #1
0
        public ActionResult Create(ContentTeam contentteam, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    //get the file name
                    string imageName = image.FileName;

                    //strip the extension from the file name
                    string ext = imageName.Substring(imageName.LastIndexOf("."));

                    //generate a guid for the new image name
                    string imageRename = Guid.NewGuid().ToString();

                    imageRename += ext;

                    //save the image to the productImages folder
                    image.SaveAs(Server.MapPath("~/Content/img/teamPhotos/" + imageRename));

                    //save the imageName to the Product Object
                    contentteam.TeamImage = imageRename;
                }
                if (image == null)
                {
                    contentteam.TeamImage = "noPhoto.jpg";
                }

                db.ContentTeams.AddObject(contentteam);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(contentteam);
        }
コード例 #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ContentTeams EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToContentTeams(ContentTeam contentTeam)
 {
     base.AddObject("ContentTeams", contentTeam);
 }
コード例 #3
0
        public ActionResult Edit(ContentTeam contentteam, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    //get the file name
                    string imageName = image.FileName;

                    //strip the extension from the file name
                    string ext = imageName.Substring(imageName.LastIndexOf("."));

                    //generate a guid for the new image name
                    string imageRename = Guid.NewGuid().ToString();

                    imageRename += ext;

                    //save the image to the productImages folder
                    image.SaveAs(Server.MapPath("~/Content/img/teamPhotos/" + imageRename));

                    //save the imageName to the Product Object
                    contentteam.TeamImage = imageRename;
                }
                else
                {
                    contentteam.TeamImage = (from i in db.ContentTeams
                                             where i.TeamID == contentteam.TeamID
                                             select i.TeamImage).Single();
                }

                db.ContentTeams.Attach(contentteam);
                db.ObjectStateManager.ChangeObjectState(contentteam, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(contentteam);
        }
コード例 #4
0
 /// <summary>
 /// Create a new ContentTeam object.
 /// </summary>
 /// <param name="teamID">Initial value of the TeamID property.</param>
 /// <param name="teamName">Initial value of the TeamName property.</param>
 /// <param name="teamImage">Initial value of the TeamImage property.</param>
 /// <param name="teamTitle">Initial value of the TeamTitle property.</param>
 public static ContentTeam CreateContentTeam(global::System.Int32 teamID, global::System.String teamName, global::System.String teamImage, global::System.String teamTitle)
 {
     ContentTeam contentTeam = new ContentTeam();
     contentTeam.TeamID = teamID;
     contentTeam.TeamName = teamName;
     contentTeam.TeamImage = teamImage;
     contentTeam.TeamTitle = teamTitle;
     return contentTeam;
 }