public HttpResponseMessage GetImage() { CompanyPortfolioEntities db = new CompanyPortfolioEntities(); var item = (from d in db.PortfolioDetails select d).ToList(); return(Request.CreateResponse(item)); }
public IHttpActionResult PostPortfolioDetail(PortfolioDetail portfolioDetail) { // DAL.AddPortfolioDetails(portfolioDetail); //string imageName = null; var httpRequest = HttpContext.Current.Request; //upload image var postedFile = httpRequest.Files["Image"]; var fileName = portfolioDetail.CoverImage.Split('\\'); //create custom filename // imageName = new string(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-"); // imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName); var filePath = HttpContext.Current.Server.MapPath("~/Image/" + fileName.LastOrDefault()); //postedFile.SaveAs(filePath); using (CompanyPortfolioEntities db = new CompanyPortfolioEntities()) { //PortfolioDetail portfolioDetail = new PortfolioDetail() //{ // //CoverImage = httpRequest["CoverImage"] // // PortfolioID = 0, // PortfolioName = "", // CompanyID = 0, // PortfolioDescription = "", // CoverImage = filePath, // YouTubeUrl = "" //}; //db.PortfolioDetails.Add(portfolioDetail); //db.SaveChanges(); var customers = db.PortfolioDetails.Add(new PortfolioDetail { CoverImage = fileName.LastOrDefault(), PortfolioName = portfolioDetail.PortfolioName, CompanyID = portfolioDetail.CompanyID, PortfolioDescription = portfolioDetail.PortfolioDescription, YouTubeUrl = portfolioDetail.YouTubeUrl }); // customers.Add(new Customer { CustomerId = id, Name = "John Doe" }); db.SaveChanges(); } // return Request.CreateResponse(HttpStatusCode.Created); return(CreatedAtRoute("DefaultApi", new { id = portfolioDetail.PortfolioID }, portfolioDetail)); }