Пример #1
0
        public ActionResult Register(Car model)
        {
            CarsDTO dto = new CarsDTO();

            CarsDAO dao = new CarsDAO();

            if (ModelState.IsValid)
            {
                dto.Name  = model.Name;
                dto.Price = model.Price;


                if (model.Price < 1000000)
                {
                    ViewBag.msg = "Too Low Price!!!";
                    return(View("Index"));
                }
                else
                {
                    var     login = Session["login1"];
                    UserDTO dto1  = new UserDTO();
                    dto1.TxtLogin = (string)login;
                    dao.purchaseCar(dto1, dto);
                    return(View("Index"));
                }
            }

            return(View("Signup"));
        }
Пример #2
0
        public async Task <CarsDTO> GetCarPrice(int id)
        {
            var client   = _httpClientFactory.CreateClient(Constants.ClientWithToken);
            var response = await client.GetAsync <CarsDTO>(string.Format(Constants.Routes.GetCarById, id));

            var price = response.Object.RetailPrice.GetValueOrDefault();

            //get vat
            var response2 = await client.GetAsync <decimal>(string.Format(Constants.Routes.CalculateVAT, price));

            var vat = response2.Object;

            var total = price + vat;

            var totalstring = CurrencyConverter.formatAmount(total);
            var pricestring = CurrencyConverter.formatAmount(price);
            var VatString   = CurrencyConverter.formatAmount(vat);

            var model = new CarsDTO
            {
                TotalToPay = totalstring,
                Amount     = pricestring,
                VAT        = VatString
            };

            return(model);
        }
Пример #3
0
        public static void Query1()
        {
            InitializeMapperQ1();

            using (var db = new CarDealerContext())
            {
                var xmlDoc = new XDocument();

                var cars = new CarsDTO()
                {
                    Cars = db.Cars
                           .ProjectTo <CarDTO>()
                           .Where(c => c.travelledDistance > 2 * Math.Pow(10, 6))
                           .OrderBy(c => c.make).ThenBy(c => c.model)
                           .ToList()
                };

                var serializer = new XmlSerializer(typeof(CarsDTO));
                var writer     = new StreamWriter("../../Export/cars.xml");

                using (writer)
                {
                    serializer.Serialize(writer, cars);
                }
            }
        }
Пример #4
0
        public async Task <IActionResult> AddCarPost(CarsDTO model)
        {
            var client = _httpClientFactory.CreateClient(Constants.ClientWithToken);

            model.Color     = model.Colors.ToString();
            model.Status    = model.Statuses.ToString();
            model.Condition = model.Conditions.ToString();

            CarColor col = StringToEnumConverter.ParseEnum <CarColor>("Ash");

            var response = await client.PostAsJsonAsync <CarsDTO, bool>(Constants.Routes.AddCar, model);

            var items = response.Object;

            if (response.ValidationErrors.Count > 0)
            {
                TempData["error"] = "An Error Occurred " + response.Code + ": " + response.ShortDescription;
                return(View("AddNewCar", model));
                //return RedirectToAction("AddNewCar");
            }
            else
            {
                //return View("AddNewCar", model);
                return(RedirectToAction("GetAllCars"));
            }
        }
Пример #5
0
        public List <CarsDTO> getRecord(UserDTO udto)
        {
            SqlDataReader dr;
            DBHelper      db = new DBHelper();

            int uid = getUserID(udto);
            //int cid = getCarID(cdto);

            string q = "select * from Cars c,PurchaseRecord p,Users u where u.UID = " + uid + " and p.UID = " + uid + " and c.CID = p.CID ";

            try
            {
                dr = db.ExecuteReader(q);
                List <CarsDTO> list = new List <CarsDTO>();
                while (dr.Read())
                {
                    CarsDTO dto = new CarsDTO();
                    dto.Name  = dr["CName"].ToString().Trim();
                    dto.Price = Convert.ToInt32(dr["CPrice"]);

                    list.Add(dto);
                }
                return(list);
            }
            catch (Exception ex) { return(null); }
        }
Пример #6
0
        public void purchaseCar(UserDTO udto, CarsDTO cdto)
        {
            DBHelper db  = new DBHelper();
            int      uid = getUserID(udto);
            int      cid = getCarID(cdto);


            string q = "insert into PurchaseRecord (UID,CID) values(" + uid + "," + cid + ")";
            int    i = db.ExecuteQuery(q);
        }
Пример #7
0
        public int getCarID(CarsDTO dto)
        {
            DBHelper      db = new DBHelper();
            string        q  = "select * from Cars where CName = '" + dto.Name + "'";
            SqlDataReader dr = db.ExecuteReader(q);
            int           id = 0;
            string        l  = "";

            while (dr.Read())
            {
                l = dr["CName"].ToString().Trim();
                if (dto.Name == l)
                {
                    id = Convert.ToInt32(dr["CID"]);
                    return(id);
                }
            }
            return(id);
        }
Пример #8
0
        public async Task <IActionResult> EditVehiclePost(CarsDTO model)
        {
            var httpClient = _httpClientFactory.CreateClient(Constants.ClientWithToken);

            model.Color     = model.Colors.ToString();
            model.Status    = model.Statuses.ToString();
            model.Condition = model.Conditions.ToString();
            //post

            var url      = string.Format(Constants.Routes.UpdateCar, model.Id);
            var response = await httpClient.PutAsync <CarsDTO, bool>(url, model);

            var items = response.Object;

            if (response.ValidationErrors.Count > 0 || items == false)
            {
                TempData["error"] = "An Error Occurred " + response.ShortDescription;
                return(RedirectToAction("GetAllCars"));
            }
            else
            {
                return(RedirectToAction("GetAllCars"));
            }
        }