示例#1
0
        public ActionResult Create(Content content, IEnumerable<HttpPostedFileBase> images, HttpPostedFileBase pdf, HttpPostedFileBase featured)
        {
            if (ModelState.IsValid)
            {
                content.Timestamp = DateTime.Now;
                content.TimestampEdit = DateTime.Now;
                db.Content.AddObject(content);
                db.SaveChanges();

                bool IsExist = Directory.Exists(Server.MapPath("~/Content/Upload/" + content.IdContentType + "/" + content.Id));
                if (!IsExist)
                    Directory.CreateDirectory(Server.MapPath("~/Content/Upload/" + content.IdContentType + "/" + content.Id));

                if (featured != null)
                {
                    var filename = Guid.NewGuid();
                    var path = Server.MapPath("~/Content/Upload/" + content.IdContentType + "/" + content.Id) + @"\" + filename.ToString().Substring(0, 8) + ".jpg";
                    featured.SaveAs(path);
                    ContentImages __newimage = new ContentImages() { FileGUID = filename, IdContent = content.Id, URL = "/Content/Upload/" + content.IdContentType + "/" + content.Id + "/" + filename.ToString().Substring(0, 8) + ".jpg", IsDefault = true };
                    db.ContentImages.AddObject(__newimage);
                    db.SaveChanges();
                }

                foreach (var item in images)
                {
                    if (item != null)
                    {
                        var filename = Guid.NewGuid();
                        var path = Server.MapPath("~/Content/Upload/" + content.IdContentType + "/" + content.Id) + @"\" + filename.ToString().Substring(0, 8) + ".jpg";
                        item.SaveAs(path);
                        ContentImages __newimage = new ContentImages() { FileGUID = filename, IdContent = content.Id, URL = "/Content/Upload/" + content.IdContentType + "/" + content.Id + "/" + filename.ToString().Substring(0, 8) + ".jpg", IsDefault = false };
                        db.ContentImages.AddObject(__newimage);
                        db.SaveChanges();
                    }
                }

                if (pdf != null)
                {
                    var filename = Guid.NewGuid();
                    var path = Server.MapPath("~/Content/Upload/" + content.IdContentType + "/" + content.Id) + @"\" + filename.ToString().Substring(0, 8) + ".pdf";
                    pdf.SaveAs(path);
                    ContentFiles __newPDF = new ContentFiles() { FileGUID = filename, IdContent = content.Id, URL = "/Content/Upload/" + content.IdContentType + "/" + content.Id + "/" + filename.ToString().Substring(0, 8) + ".pdf", IsDefault = true };
                    db.ContentFiles.AddObject(__newPDF);
                    db.SaveChanges();
                }

                return RedirectToAction("Index", new { Id = content.IdContentType });
            }

            ViewBag.IdContentType = new SelectList(db.ContentType, "Id", "Name", content.IdContentType);
            ViewBag.IdCountry = new SelectList(db.Country, "Id", "Country1", content.IdCountry);
            return View(content);
        }
示例#2
0
 /// <summary>
 /// Create a new Content object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="intro">Initial value of the Intro property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 /// <param name="city">Initial value of the City property.</param>
 /// <param name="idCountry">Initial value of the IdCountry property.</param>
 /// <param name="idContentType">Initial value of the IdContentType property.</param>
 /// <param name="active">Initial value of the Active property.</param>
 /// <param name="featured">Initial value of the Featured property.</param>
 /// <param name="timestamp">Initial value of the Timestamp property.</param>
 /// <param name="timestampEdit">Initial value of the TimestampEdit property.</param>
 public static Content CreateContent(global::System.Int32 id, global::System.String title, global::System.String intro, global::System.String description, global::System.Decimal price, global::System.String city, global::System.Int32 idCountry, global::System.Int32 idContentType, global::System.Boolean active, global::System.Boolean featured, global::System.DateTime timestamp, global::System.DateTime timestampEdit)
 {
     Content content = new Content();
     content.Id = id;
     content.Title = title;
     content.Intro = intro;
     content.Description = description;
     content.Price = price;
     content.City = city;
     content.IdCountry = idCountry;
     content.IdContentType = idContentType;
     content.Active = active;
     content.Featured = featured;
     content.Timestamp = timestamp;
     content.TimestampEdit = timestampEdit;
     return content;
 }
示例#3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Content EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToContent(Content content)
 {
     base.AddObject("Content", content);
 }
示例#4
0
        public ActionResult Edit(Content content, IEnumerable<HttpPostedFileBase> images, HttpPostedFileBase pdf, HttpPostedFileBase featured, ContentMedia MetaData)
        {
            if (ModelState.IsValid)
            {

                content.TimestampEdit = DateTime.Now;

                db.Content.Attach(content);
                db.ObjectStateManager.ChangeObjectState(content, EntityState.Modified);
                db.SaveChanges();

                if (featured != null)
                {
                    var filename = Guid.NewGuid();
                    var path = Server.MapPath("~/Content/Upload/" + content.IdContentType + "/" + content.Id) + @"\" + filename.ToString().Substring(0, 8) + ".jpg";
                    featured.SaveAs(path);
                    ContentImages __newimage = new ContentImages() { FileGUID = filename, IdContent = content.Id, URL = "/Content/Upload/" + content.IdContentType + "/" + content.Id + "/" + filename.ToString().Substring(0, 8) + ".jpg", IsDefault = true };

                    var __todelete = db.ContentImages.Where(u => u.URL.Contains(MetaData.image)).FirstOrDefault();
                    if (__todelete != null)
                    {
                        db.ContentImages.DeleteObject(__todelete);
                        db.SaveChanges();
                    }

                    db.ContentImages.AddObject(__newimage);
                    db.SaveChanges();
                }
                int i = 1;

                foreach (var item in images)
                {
                    if (item != null)
                    {
                        var filename = Guid.NewGuid();
                        var path = Server.MapPath("~/Content/Upload/" + content.IdContentType + "/" + content.Id) + @"\" + filename.ToString().Substring(0, 8) + ".jpg";
                        item.SaveAs(path);
                        ContentImages __newimage = new ContentImages() { FileGUID = filename, IdContent = content.Id, URL = "/Content/Upload/" + content.IdContentType + "/" + content.Id + "/" + filename.ToString().Substring(0, 8) + ".jpg", IsDefault = false };

                        string namefile = string.Empty;

                        switch (i)
                        {

                            case 1:
                                namefile = MetaData.img1;
                                break;
                            case 2:
                                namefile = MetaData.img2;
                                break;
                            case 3:
                                namefile = MetaData.img3;
                                break;
                            case 4:
                                namefile = MetaData.img4;
                                break;
                            default:
                                namefile = MetaData.img1;
                                break;
                        }

                        var __todelete = db.ContentImages.Where(u => u.URL.Contains(namefile)).FirstOrDefault();
                        if (__todelete != null)
                        {
                            db.ContentImages.DeleteObject(__todelete);
                            db.SaveChanges();
                        }

                        db.ContentImages.AddObject(__newimage);
                        db.SaveChanges();
                    }
                    i = i + 1;
                }

                if (pdf != null)
                {
                    var filename = Guid.NewGuid();
                    var path = Server.MapPath("~/Content/Upload/" + content.IdContentType + "/" + content.Id) + @"\" + filename.ToString().Substring(0, 8) + ".pdf";
                    pdf.SaveAs(path);
                    ContentFiles __newPDF = new ContentFiles() { FileGUID = filename, IdContent = content.Id, URL = "/Content/Upload/" + content.IdContentType + "/" + content.Id + "/" + filename.ToString().Substring(0, 8) + ".pdf", IsDefault = true };

                    var __todelete = db.ContentFiles.Where(u => u.URL.Contains(MetaData.pdf)).FirstOrDefault();
                    if (__todelete != null)
                    {
                        db.ContentFiles.DeleteObject(__todelete);
                        db.SaveChanges();
                    }

                    db.ContentFiles.AddObject(__newPDF);
                    db.SaveChanges();
                }

                return RedirectToAction("Index", new { Id = content.IdContentType });
            }

            ViewBag.IdContentType = new SelectList(db.ContentType, "Id", "Name", content.IdContentType);
            ViewBag.IdCountry = new SelectList(db.Country, "Id", "Country1", content.IdCountry);
            return View(content);
        }