コード例 #1
0
        //[ValidateAntiForgeryToken]
        public ActionResult EditProcurement([Bind(Include = "ProcurementId, ProductName, PurchaseDate, Quantity, UnitPrize, ProductId")] Procurement procurement)
        {
            //var procurement = JsonConvert.DeserializeObject<Procurement>(procurementJson);
            ProductRepository           productRepo     = new ProductRepository(db);
            ProcurementRepository       procurementRepo = new ProcurementRepository(db);
            List <ProcurementViewModel> procurements    = new List <ProcurementViewModel>();

            //將變更儲存在資料庫
            if (ModelState.IsValid)
            {
                db.Entry(procurement).State = EntityState.Modified;
                db.SaveChanges();
            }
            //抓取改變後的資料
            foreach (Procurement item in procurementRepo.GetAll().ToList())
            {
                ProcurementViewModel procurementVM = new ProcurementViewModel()
                {
                    ProductName   = productRepo.GetProductNameByID(item.ProductId),
                    ProcurementId = item.ProcurementId,
                    PurchaseDate  = item.PurchaseDate.ToString("yyyy/MM/dd hh:mm:ss"),
                    Quantity      = item.Quantity,
                    UnitPrize     = item.UnitPrize,
                };
                procurements.Add(procurementVM);
            }
            return(Json(procurements));
        }
コード例 #2
0
        public ActionResult CreateProcurement([Bind(Include = "ProductId,PurchaseDate,Quantity,UnitPrize")] Procurement procurement)
        {
            ProductRepository           productRepo     = new ProductRepository(db);
            ProcurementRepository       procurementRepo = new ProcurementRepository(db);
            List <ProcurementViewModel> procurements    = new List <ProcurementViewModel>();

            //將輸入資料儲存在資料庫
            if (ModelState.IsValid)
            {
                db.Procurement.Add(procurement);
                db.SaveChanges();
            }
            //抓取改變後的資料
            foreach (Procurement item in procurementRepo.GetAll().ToList())
            {
                ProcurementViewModel procurementVM = new ProcurementViewModel()
                {
                    ProductName   = productRepo.GetProductNameByID(item.ProductId),
                    ProcurementId = item.ProcurementId,
                    PurchaseDate  = item.PurchaseDate.ToString("yyyy/MM/dd hh:mm:ss"),
                    Quantity      = item.Quantity,
                    UnitPrize     = item.UnitPrize,
                };
                procurements.Add(procurementVM);
            }
            return(Json(procurements));
        }
コード例 #3
0
        public ActionResult GetPricePerMonthChartData()
        {
            ProcurementRepository procurementRepo = new ProcurementRepository(db);
            ChartViewModel        chartViewModel  = new ChartViewModel();
            var procurement = from p in procurementRepo.GetAll()
                              group p by new { p.PurchaseDate.Year, p.PurchaseDate.Month } into g
                select new
            {
                YM         = g.Key.Year + "/" + g.Key.Month,
                PriceTotal = g.Sum(p => p.Quantity * p.UnitPrize)
            };

            foreach (var p in procurement)
            {
                chartViewModel.Label.Add(p.YM);
                chartViewModel.Data.Add(p.PriceTotal);
            }
            return(Json(chartViewModel, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public ActionResult DeleteProcurement(int?id)
        {
            ProductRepository           productRepo     = new ProductRepository(db);
            ProcurementRepository       procurementRepo = new ProcurementRepository(db);
            List <ProcurementViewModel> procurements    = new List <ProcurementViewModel>();

            if (id == null)
            {
                foreach (Procurement item in procurementRepo.GetAll().ToList())
                {
                    ProcurementViewModel procurementVM = new ProcurementViewModel()
                    {
                        ProductName   = productRepo.GetProductNameByID(item.ProductId),
                        ProcurementId = item.ProcurementId,
                        PurchaseDate  = item.PurchaseDate.ToString("yyyy/MM/dd hh:mm:ss"),
                        Quantity      = item.Quantity,
                        UnitPrize     = item.UnitPrize,
                    };
                    procurements.Add(procurementVM);
                }
                return(Json(procurements));
            }
            Procurement procurement = db.Procurement.Find(id);

            db.Procurement.Remove(procurement);
            db.SaveChanges();

            foreach (Procurement item in procurementRepo.GetAll().ToList())
            {
                ProcurementViewModel procurementVM = new ProcurementViewModel()
                {
                    ProductName   = productRepo.GetProductNameByID(item.ProductId),
                    ProcurementId = item.ProcurementId,
                    PurchaseDate  = item.PurchaseDate.ToString("yyyy/MM/dd hh:mm:ss"),
                    Quantity      = item.Quantity,
                    UnitPrize     = item.UnitPrize,
                };
                procurements.Add(procurementVM);
            }
            return(Json(procurements));
        }
コード例 #5
0
        public ActionResult GetAllProcurements() //拿到所有訂單資料
        {
            ProductRepository           productRepo     = new ProductRepository(db);
            ProcurementRepository       procurementRepo = new ProcurementRepository(db);
            List <ProcurementViewModel> procurements    = new List <ProcurementViewModel>();

            foreach (Procurement item in procurementRepo.GetAll().ToList())
            {
                ProcurementViewModel procurementVM = new ProcurementViewModel()
                {
                    ProcurementId = item.ProcurementId,
                    ProductName   = productRepo.GetProductNameByID(item.ProductId),
                    PurchaseDate  = item.PurchaseDate.ToString("yyyy/MM/dd hh:mm:ss"),
                    Quantity      = item.Quantity,
                    UnitPrize     = item.UnitPrize,
                    ProductId     = item.ProductId
                };
                procurements.Add(procurementVM);
            }

            return(Json(procurements, JsonRequestBehavior.AllowGet));
        }