コード例 #1
0
        public ActionResult Create()
        {
            ListAutoPrice newObj = new ListAutoPrice();

            foreach (var item in db.SACHes.ToList())
            {
                var check = db.BANGGIAs.Where(bg => bg.ID_SACH == item.ID_SACH).FirstOrDefault();
                if (check == null)
                {
                    newObj.lsDepend.Add(item);
                }
            }
            DateTime needDate = DateTime.Now.AddDays(1);
            string   date     = needDate.Day.ToString();

            if (date.Length == 1)
            {
                date = "0" + date;
            }
            string month = needDate.Month.ToString();

            if (month.Length == 1)
            {
                month = "0" + month;
            }
            newObj.minDate = needDate.Year.ToString() + "-" + month + "-" + date;
            return(View(newObj));
        }
コード例 #2
0
        public ActionResult Create(ListAutoPrice obj)
        {
            string        ngayApDung = obj.ngayApDung;
            bool          tangGiam   = obj.tangGiam == "down" ? false : true;
            double        giaTri     = obj.giaTri;
            bool          donVi      = obj.donVi == "VND" ? true : false;
            ListAutoPrice newObj     = new ListAutoPrice();

            foreach (var item in db.SACHes.ToList())
            {
                var check = db.BANGGIAs.Where(bg => bg.ID_SACH == item.ID_SACH).FirstOrDefault();
                if (check == null)
                {
                    newObj.lsDepend.Add(item);
                }
            }
            // Ko nhận dc ls
            foreach (var item in newObj.lsDepend)
            {
                BANGGIA newBG = new BANGGIA();
                newBG.ID_SACH     = item.ID_SACH;
                newBG.NGAY_APDUNG = ngayApDung;
                newBG.TANG_GIAM   = tangGiam;
                if (donVi)
                {
                    newBG.GIATRI = giaTri;
                }
                else
                {
                    newBG.GIATRI = (item.GIA_BAN * giaTri) / 100;
                }
                db.BANGGIAs.Add(newBG);
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }