public JsonResult Delete(int Id)
        {
            ProductSolds productSold = db.ProductSolds.Find(Id);

            db.ProductSolds.Remove(productSold);
            db.SaveChanges();
            return(Json("Success", JsonRequestBehavior.AllowGet));
        }
        public bool Delete(int id)
        {
            ProductSolds productSold = db.ProductSolds.Find(id);

            db.ProductSolds.Remove(productSold);
            db.SaveChanges();
            return(true);
        }
        private ProductSolds convertToProductSolds(ProductSold p)
        {
            ProductSolds s = new ProductSolds
            {
                Id         = p.Id,
                CustomerId = p.CustomerId,
                ProductId  = p.ProductId,
                StoreId    = p.StoreId,
                DateSold   = p.DateSold
            };

            return(s);
        }
        public object GetById(int id)
        {
            ProductSolds c    = db.ProductSolds.Find(id);
            ProductSold  sale = new ProductSold
            {
                Id           = c.Id,
                CustomerId   = c.CustomerId,
                CustomerName = c.Customers.Name,
                ProductId    = c.ProductId,
                ProductName  = c.Products.Name,
                StoreId      = c.StoreId,
                StoreName    = c.Stores.Name,
                DateSold     = c.DateSold
            };

            return(sale);
        }
        public bool Update(object item)
        {
            if (item == null)
            {
                return(false);
            }

            ProductSold i = (ProductSold)item;
            //i.DateSold = Convert.ToDateTime(i.DateSoldString); // this line is no longer needed as we are no longer binding DateSoldString
            ProductSolds sale = convertToProductSolds(i);

            var p = db.ProductSolds.FirstOrDefault(a => a.Id == sale.Id);

            p.CustomerId = sale.CustomerId;
            p.ProductId  = sale.ProductId;
            p.StoreId    = sale.StoreId;
            p.DateSold   = sale.DateSold;
            db.SaveChanges();
            return(true);
        }
        public object Add(object item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            //define DateSoldString property
            ProductSold productSold = (ProductSold)item;

            //has to set its DateSoldString so we can pass it later to the display oberservable array to display
            productSold.DateSoldString = productSold.DateSold.ToString("dd/MM/yyyy");

            //convert to main database context ProductSolds table object and save to table
            ProductSolds sale = convertToProductSolds(productSold);

            db.ProductSolds.Add(sale);
            db.SaveChanges();

            //get ID of the sale row we just added from main database
            productSold.Id = sale.Id;
            return(productSold);
        }
 public JsonResult update(ProductSolds productSold)
 {
     db.Entry(productSold).State = EntityState.Modified;
     db.SaveChanges();
     return(Json("Update complete.", JsonRequestBehavior.AllowGet));
 }
 public JsonResult Add(ProductSolds productSold)
 {
     db.ProductSolds.Add(productSold);
     db.SaveChanges();
     return(Json("Added", JsonRequestBehavior.AllowGet));
 }