public ActionResult Index(Product product, HttpPostedFileBase FileUpload)
 {
     using (AlliedEntities db = new AlliedEntities())
     {
         try
         {
             if (ModelState.IsValid)
             {
                 ViewBag.Msg = null;
                 if (FileUpload != null)
                 {
                     if (FileUpload.ContentLength <= (512 * 512) && (FileUpload.ContentType.Contains("/jpg") || FileUpload.ContentType.Contains("/jpeg") || FileUpload.ContentType.Contains("/png") || FileUpload.ContentType.Contains("/bmp")))
                     {
                         product.imagetype = FileUpload.ContentType;
                         product.imagebytes = ConverToByte(FileUpload);
                         ViewBag.Msg = null;
                     }
                     else
                     {
                         ViewBag.Msg = "Invalid File";
                     }
                 }
                 if (ViewBag.Msg == null)
                 {
                     db.Products.Attach(product);
                     db.ObjectStateManager.ChangeObjectState(product, System.Data.EntityState.Modified);
                     db.SaveChanges();
                     return RedirectToAction("Index", "Manage");
                 }
                 else
                 {
                     var q = (from p in db.Products
                              where p.id == product.id
                              select p).FirstOrDefault();
                     ViewBag.Msg = "Something went wrong";
                     return View(q);
                 }
                 
             }
             else
             {
                 var q = (from p in db.Products
                          where p.id == product.id
                          select p).FirstOrDefault();
                 ViewBag.Msg = "Something went wrong";
                 return View(q);
             }
         }
         catch (Exception e)
         {
             var q = (from p in db.Products
                      where p.id == product.id
                      select p).FirstOrDefault();
             ViewBag.Msg = "Something went wrong";
             return View(q);
         }
     }
 }
 public ActionResult Index(Product item, HttpPostedFileBase FileUpload)
 {
     if (ModelState.IsValid){
         try{
             using(AlliedEntities db = new AlliedEntities()){
                 if (FileUpload != null)
                 {
                     if (FileUpload.ContentLength <= (512 * 512) && (FileUpload.ContentType.Contains("/jpg") || FileUpload.ContentType.Contains("/jpeg") || FileUpload.ContentType.Contains("/png") || FileUpload.ContentType.Contains("/bmp")))
                     {
                         item.imagetype = FileUpload.ContentType;
                         item.imagebytes = ConverToByte(FileUpload);
                         ViewBag.Msg = null;
                     }
                     else
                     {
                         ViewBag.Msg = "Invalid File";
                     }
                 }
                 if (ViewBag.Msg == null)
                 {
                     item.dateadded = DateTime.Now.Date;
                     db.Products.AddObject(item);
                     db.SaveChanges();
                     ViewBag.Msg = "Successfully Added";
                     return View();
                 }
                 else
                 {
                     return View();
                 }
             }
         }
         catch (Exception)
         {
             return View();
         }
     }
     return View();
 }
 /// <summary>
 /// Create a new Product object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="title">Initial value of the title property.</param>
 /// <param name="category">Initial value of the category property.</param>
 /// <param name="imagetype">Initial value of the imagetype property.</param>
 /// <param name="imagebytes">Initial value of the imagebytes property.</param>
 /// <param name="dateadded">Initial value of the dateadded property.</param>
 public static Product CreateProduct(global::System.Int32 id, global::System.String title, global::System.String category, global::System.String imagetype, global::System.Byte[] imagebytes, global::System.DateTime dateadded)
 {
     Product product = new Product();
     product.id = id;
     product.title = title;
     product.category = category;
     product.imagetype = imagetype;
     product.imagebytes = imagebytes;
     product.dateadded = dateadded;
     return product;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Products EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProducts(Product product)
 {
     base.AddObject("Products", product);
 }