示例#1
0
        public ActionResult Create(ViewRent rent)
        {
            if (rent.RentPriceText != null)
            {
                var PriceText = rent.RentPriceText;
                PriceText.Replace(",", string.Empty);
                var Price = Convert.ToDecimal(PriceText);
                rent.RentPrice = Price;
            }
            var Data = new Rent
            {
                MachineId  = rent.MachineId,
                CustomerId = rent.CustomerId,
                StartDate  = rent.StartDate,
                EndDate    = rent.EndDate,
                Remark     = rent.Remark,
                RentPrice  = rent.RentPrice
            };

            if (ModelState.IsValid)
            {
                db.Rents.Add(Data);
                db.SaveChanges();

                //<-- Update Status in tbl Machine to "Rent" -->
                Machine machine = db.Machines.Find(Data.MachineId);
                machine.Status          = "Rent";
                db.Entry(machine).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Details/" + Data.Id));
            }
            return(View(rent));
        }
示例#2
0
        public ActionResult Edit(ViewRent rent)
        {
            if (rent.RentPriceText != null)
            {
                var PriceText = rent.RentPriceText;
                PriceText.Replace(",", string.Empty);
                var Price = Convert.ToDecimal(PriceText);
                rent.RentPrice = Price;
            }
            var Data = new Rent
            {
                Id         = rent.Id,
                MachineId  = rent.MachineId,
                CustomerId = rent.CustomerId,
                StartDate  = rent.StartDate,
                EndDate    = rent.EndDate,
                ReturnDate = rent.ReturnDate,
                RentPrice  = rent.RentPrice,
                Remark     = rent.Remark,
            };

            if (ModelState.IsValid)
            {
                db.Entry(Data).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Details/" + Data.Id));
            }
            return(View(rent));
        }