Exemplo n.º 1
0
 public void UpdateItem(Fruit fruit, int quantity)
 {
     CartLine line = lineCollection
         .Where(p => p.Fruit.Id == fruit.Id)
         .FirstOrDefault();
     if (line != null)
     {
       
         line.Quantity = quantity;
     }
 }
 public ActionResult Create(Fruit fruit)
 {
      using (FarmstoreEntities dbContext = new FarmstoreEntities())
     {
         
         dbContext.Fruits.Attach(fruit);
         dbContext.Entry(fruit).State = System.Data.Entity.EntityState.Added;
         dbContext.SaveChanges();
     }
     return RedirectToAction("Index", new { pageNumber = 1 });  
 }
Exemplo n.º 3
0
        public void AddItem(Fruit fruit, int quantity)
        {
            CartLine line = lineCollection
                .Where(f => f.Fruit.Id == fruit.Id)
                .FirstOrDefault();
            if (line == null)
            {
                lineCollection.Add(new CartLine { Fruit = fruit, Quantity = quantity });

            }
            else
            {
                line.Quantity += quantity;
            }
        }
        public ActionResult Edit(Fruit fruit)
        {

            using (FarmstoreEntities dbContext = new FarmstoreEntities())
            {
                if (this.Request.Files != null && this.Request.Files.Count > 0 &&  //4 for upload file
                    this.Request.Files[0].ContentLength > 0 &&
                    this.Request.Files[0].ContentLength < 1024 * 120)  //file size less than 120K
                {

                    string fileName = Path.GetFileName(this.Request.Files[0].FileName);
                    string pathOfWebsite = "~/Images/Fruits/" + fileName;
                    fruit.FruitImagePath = pathOfWebsite;
                    this.Request.Files[0].SaveAs(this.Server.MapPath(pathOfWebsite));

                }
               
                    dbContext.Fruits.Attach(fruit);
                    dbContext.Entry(fruit).State = System.Data.Entity.EntityState.Modified;
                    dbContext.SaveChanges();
               
            }
            return RedirectToAction("Index", new { pageNumber = 1 });  //4 for paging
        }
Exemplo n.º 5
0
        public void RemoveLine(Fruit fruit)
        {
            lineCollection.RemoveAll(l => l.Fruit.Id == fruit.Id);

        }