Esempio n. 1
0
        public int myProduct(HttpPostedFileBase file, Product product)
        {
            product.Image = ConvertToBytes(file);
            //contentViewModel.UserId = User.Identity.GetUserId();

            var Product = new Product
            {
                SubCatId    = product.SubCatId,
                Name        = product.Name,
                Price       = product.Price,
                Quantity    = product.Quantity,
                Other       = product.Other,
                Description = product.Description,
                Image       = product.Image,
                BarCode     = product.BarCode
            };


            db.Products.Add(Product);
            int i = db.SaveChanges();


            if (i == 1)
            {
                return(Product.Id);
            }
            else
            {
                return(0);
            }


            return(0);
        }
        public JsonResult SaveOrder(CategoryAndProduct cp)
        {
            bool status = false;

            using (RotanaContext dc = new RotanaContext())
            {
                Order order = new Order
                {
                    UserId       = cp.UserId,
                    OrderDate    = cp.OrderDate,
                    CustomerName = cp.CustomerName,
                    Address      = cp.Address,
                    City         = cp.City,
                    PhoneNumber  = cp.PhoneNumber
                };
                foreach (var i in cp.OrderProducts)
                {
                    /*OrderProduct orderp = new OrderProduct
                     * {
                     *  OrderId = i.OrderId,
                     *  ProductId = i.ProductId,
                     *  ProductName = i.ProductName,
                     *  UnitPrice = i.UnitPrice,
                     *  UnitQuantity = i.UnitQuantity
                     *
                     * };
                     * dc.OrderProducts.Add(orderp);
                     * dc.SaveChanges();*/
                    order.OrderProducts.Add(i);
                }
                dc.Orders.Add(order);
                dc.SaveChanges();

                /*int id =  order.Id;
                 * foreach (var i in cp.OrderProducts)
                 * {
                 *  OrderProduct orderp = new OrderProduct
                 *  {
                 *      OrderId = order.Id,
                 *      ProductId = i.ProductId,
                 *      ProductName = i.ProductName,
                 *      UnitPrice = i.UnitPrice,
                 *      UnitQuantity = i.UnitQuantity
                 *
                 *  };
                 *  dc.OrderProducts.Add(orderp);
                 *  dc.SaveChanges();
                 *
                 * }*/
                status = true;
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "Id,Name,Address,City,PhoneNumber")] Branch branch)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Branches.Add(branch);
                    db.SaveChanges();
                    return(RedirectToAction("Create"));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }


            return(View(branch));
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "Id,BranchId,DateStart,DateEnd,Name,Address,City,PhoneNumber")] Employee employee)
        {
            PopulateBranchesDropDownList(employee.BranchId);
            try
            {
                if (ModelState.IsValid)
                {
                    db.Employees.Add(employee);
                    db.SaveChanges();
                    return(RedirectToAction("Create"));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }

            return(View(employee));
        }