Example #1
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Height heights)
 {
     if (ModelState.IsValid)
     {
         db.Entry(heights).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(heights));
 }
Example #2
0
 public ActionResult Edit([Bind(Include = "BadBeeNumber,BadBeeNumberId")] BadBee.Core.DAL.BadBee BadBeeNumbers)
 {
     if (ModelState.IsValid)
     {
         db.Entry(BadBeeNumbers).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(BadBeeNumbers));
 }
Example #3
0
 public ActionResult Edit([Bind(Include = "Name,Id")] Brand brands)
 {
     if (ModelState.IsValid)
     {
         db.Entry(brands).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(brands));
 }
Example #4
0
 public ActionResult Edit([Bind(Include = "DimensionId,WidthId,HeightId,ThicknessId")] Dimension dimension)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dimension).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.HeightId    = new SelectList(db.Height, "HeightId", "HeightId", dimension.HeightId);
     ViewBag.ThicknessId = new SelectList(db.Thickness, "ThicknessId", "ThicknessId", dimension.ThicknessId);
     ViewBag.WidthId     = new SelectList(db.Width, "WidthId", "WidthId", dimension.WidthId);
     return(View(dimension));
 }
 public ActionResult Edit([Bind(Include = "Name,Id")] Wva wva)
 {
     try {
         if (ModelState.IsValid)
         {
             db.Entry(wva).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(wva));
     }
     catch (Exception ex)
     {
         log.Error(ex);
         throw ex;
     }
 }
        public ActionResult FileUpload(HttpPostedFileBase file, string caption, string type, string BadBees)
        {
            try
            {
                Item ifExist = db.Item.Where(q => (q.BadBee.BadBeeNo == BadBees)).FirstOrDefault();
                if (ifExist == null)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    PicturesModel pictures = new PicturesModel();

                    if (file != null)
                    {
                        if (!string.IsNullOrEmpty(BadBees))
                        {
                            caption = BadBees;
                        }

                        string pic  = "";
                        string path = "";

                        if (type == "schema1")
                        {
                            pic = Path.GetFileName(caption + "a.jpg");
                        }
                        else if (type == "schema2")
                        {
                            pic = Path.GetFileName(caption + "b.jpg");
                        }
                        else if (type == "picture2")
                        {
                            pic = Path.GetFileName(caption + "_2.jpg");
                        }
                        else if (type == "picture1")
                        {
                            pic = Path.GetFileName(caption + "_1.jpg");
                        }

                        if (BadBees == null)
                        {
                            BadBees = "";
                        }

                        Picture obj = db.Picture.Where(q => (q.BadBeeNo == BadBees)).FirstOrDefault();

                        if (obj != null)
                        {
                            List <Item> product = db.Item.Where(q => (q.BadBee.BadBeeNo == obj.BadBeeNo)).ToList();

                            if (type == "schema1" && obj.Picture1 != pic)
                            {
                                obj.Picture1 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture1).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }
                            if (type == "schema2" && obj.Picture2 != pic)
                            {
                                obj.Picture2 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture2).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }
                            if (type == "picture2" && obj.Picture3 != pic)
                            {
                                obj.Picture3 = pic;
                                using (var dbCtx = new BadBeeEntities())
                                {
                                    db.Picture.Attach(obj);
                                    db.Entry(obj).Property(x => x.Picture3).IsModified = true;
                                    dbCtx.SaveChanges();
                                }
                            }

                            Picture newPict = new Picture();
                            newPict = db.Picture.Where(q => q.PictureId == obj.PictureId).FirstOrDefault();
                        }
                        else
                        {
                            Picture newObj = new Picture();
                            //var np = db.Pictures.OrderByDescending(q => q.Id).Select(q => q).FirstOrDefault();
                            //int newid = np.Id + 1;

                            //newObj.BadBeeNo = BadBees;
                            //if (type == "schema1") { newObj.Schema1 = pic; };
                            //if (type == "schema2") { newObj.Schema2 = pic; };

                            //if (type == "picture1") { newObj.Picture1 = pic; };
                            //if (type == "picture2") { newObj.Picture2 = pic; };
                            //newObj.Id = newid;

                            //List<ItemsDb> product = db.ItemsDb.Where(q => (q.BadBeeNumber == newObj.BadBeeNo)).ToList();
                            //foreach (var item in product)
                            //{
                            //    item.PictureId = newObj.Id;
                            //}

                            using (var dbCtx = new BadBeeEntities())
                            {
                                dbCtx.Picture.Add(newObj);
                                dbCtx.SaveChanges();
                            }
                        }

                        path = Path.Combine(Server.MapPath("~/Images/Pictures"), pic);

                        // file is uploaded

                        file.SaveAs(path);

                        using (MemoryStream ms = new MemoryStream())
                        {
                            file.InputStream.CopyTo(ms);
                            byte[] array = ms.GetBuffer();
                        }

                        db.SaveChanges();
                    }
                    //}
                    // after successfully uploading redirect the user
                    return(RedirectToAction("List", pictures));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
        }