public ActionResult Create(FormCollection form, HttpPostedFileBase uploadFile) { using (var context = new ModelContainer()) { var project = new Project { ImageSource = "" }; TryUpdateModel(project, new[] { "Name", "Title", "SortOrder" }); string fileName = IOHelper.GetUniqueFileName("~/Content/Images", uploadFile.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); uploadFile.SaveAs(filePath); project.ImageSource = fileName; project.TextTop = HttpUtility.HtmlDecode(form["TextTop"]); project.TextBottom = HttpUtility.HtmlDecode(form["TextBottom"]); context.AddToProject(project); context.SaveChanges(); return RedirectToAction("Index", "Home", new { Area = "", id = "projects" }); } }
public ProjectsModel(ModelContainer dataContext, string contentId, string projectId, bool loadContent=true) : base(dataContext, contentId, projectId, loadContent) { Projects = _context.Project.ToList(); if (!string.IsNullOrEmpty(projectId)) { Project = _context.Project.Include("ProjectItems").First(p => p.Name == projectId); Title += " - " + Project.Title; } }
/// <summary> /// Deprecated Method for adding a new object to the Project EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToProject(Project project) { base.AddObject("Project", project); }
/// <summary> /// Create a new Project object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="imageSource">Initial value of the ImageSource property.</param> /// <param name="name">Initial value of the Name property.</param> public static Project CreateProject(global::System.Int32 id, global::System.String title, global::System.String imageSource, global::System.String name) { Project project = new Project(); project.Id = id; project.Title = title; project.ImageSource = imageSource; project.Name = name; return project; }