Exemplo n.º 1
0
 public void TakeCar(int?carId)
 {
     if (carId != null)
     {
         db.Cars.Find(carId).isTaken = true;
         db.SaveChanges();
     }
 }
        public void CompleteQuery(int?queryId)
        {
            if (queryId != null)
            {
                db.CustomerFavours.Find(queryId).isCompleted = true;

                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public void CloseDeal(int?rentId)
        {
            if (rentId != null)
            {
                db.Rents.Find(rentId).isClosed = true;

                db.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public string Execute(IList <string> parameters)
        {
            using (var contextDb = new AutoRentContext())
            {
                XmlDocument xmldoc  = new XmlDocument();
                var         xmlfile = File.ReadAllText(@"cars.xml");
                xmldoc.LoadXml(xmlfile);

                XmlElement  root  = xmldoc.DocumentElement;
                XmlNodeList nodes = root.SelectNodes("row");
                foreach (XmlNode node in nodes)
                {
                    var car = new Car()
                    {
                        Type     = node.ChildNodes.Item(0).FirstChild.InnerText,
                        Model    = node.ChildNodes.Item(1).FirstChild.InnerText,
                        Make     = node.ChildNodes.Item(2).FirstChild.InnerText,
                        Price    = decimal.Parse(node.ChildNodes.Item(3).FirstChild.InnerText),
                        OfficeId = int.Parse(node.ChildNodes.Item(4).FirstChild.InnerText),
                    };

                    contextDb.Cars.Add(car);
                }
                contextDb.SaveChanges();
            }

            return("Cars loaded from XML to database!");
        }
Exemplo n.º 5
0
        public string Execute(IList <string> parameters)
        {
            using (var contextDb = new AutoRentContext())
            {
                var json = File.ReadAllText(@"offices.json");
                var list = JsonConvert.DeserializeObject <List <Office> >(json);
                foreach (var office in list)
                {
                    contextDb.Offices.Add(office);
                }
                contextDb.SaveChanges();
            }

            return("Offices loaded from JSON to database!");
        }
Exemplo n.º 6
0
        public ActionResult AddPayment()
        {
            if (TempData["Payment"] != null)
            {
                var payment = (Payment)TempData["Payment"];

                carsController.ReleaseCar(db.Rents.Find(payment.RentID).CarID);

                dealsController.CloseDeal(payment.RentID);

                db.Payments.Add(payment);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public ActionResult CreateCustomer([Bind(Include = "ID,firstName,lastName,middleName,passportDetails,phoneNumber,discountPercentage")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                if (!customer.discountPercentage.HasValue)
                {
                    customer.discountPercentage = 0;
                }
                else
                {
                    customer.discountPercentage /= 100;
                }

                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }