Esempio n. 1
0
        public JsonResult SaveSale(int Id, int ProductId, int CustomerId, int StoreId, DateTime SaleDate)
        {
            //This method is used to save the edited information about the Customer  and to create a new
            //method
            var result = false;

            if (Id > 0)
            {
                try

                {
                    ProductSold SaleToBeUpdated = db.ProductSolds.SingleOrDefault(x => x.Id == Id);
                    SaleToBeUpdated.ProductId  = ProductId;
                    SaleToBeUpdated.CustomerId = CustomerId;
                    SaleToBeUpdated.StoreId    = StoreId;
                    SaleToBeUpdated.Date       = SaleDate;

                    db.SaveChanges();
                    result = true;
                }
                catch (Exception exp)
                {
                }
            }

            else
            {
                //The following code insersts new record
                try
                {
                    CustomerDbEntities db   = new CustomerDbEntities();
                    ProductSold        Sale = new ProductSold();
                    Sale.ProductId  = ProductId;
                    Sale.CustomerId = CustomerId;
                    Sale.StoreId    = StoreId;
                    Sale.Date       = SaleDate;
                    db.ProductSolds.Add(Sale);
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveProduct(int Id, string Name, Decimal Price)
        {
            var result = false;

            if (Id > 0)
            {
                try

                {
                    Product ProducttoBeUpdated = db.Products.SingleOrDefault(x => x.Id == Id);
                    ProducttoBeUpdated.Name  = Name;
                    ProducttoBeUpdated.Price = Price;
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception exp)
                {
                }
            }

            else
            {
                //The following code insersts new record
                try
                {
                    CustomerDbEntities db = new CustomerDbEntities();

                    // List<Product> list = db.Products.ToList();
                    //ViewBag.DepartmentList = new SelectList(list, "DepartmentId", "DepartmentName");

                    Product P1 = new Product();

                    P1.Name  = Name;
                    P1.Price = Price;
                    db.Products.Add(P1);
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveCustomer(int Id, string Name, string Address)
        {
            //This method is used to save the edited information about the Customer  and to create a new
            //method
            var result = false;

            if (Id > 0)
            {
                try

                {
                    Customer CustomertoBeUpdated = db.Customers.SingleOrDefault(x => x.Id == Id);
                    CustomertoBeUpdated.Name    = Name;
                    CustomertoBeUpdated.Address = Address;
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception exp)
                {
                }
            }

            else
            {
                //The following code insersts new record
                try
                {
                    CustomerDbEntities db          = new CustomerDbEntities();
                    Customer           newCustomer = new Customer();
                    newCustomer.Name    = Name;
                    newCustomer.Address = Address;
                    db.Customers.Add(newCustomer);
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
 public CustomerRepository(CustomerDbEntities context) : base(context)
 {
     _customerDbEntities = context;
 }
Esempio n. 5
0
 public UnitOfWork(CustomerDbEntities context)
 {
     _context  = context;
     Customers = new CustomerRepository(_context);
 }