コード例 #1
0
        public static void UpdateRentedCarStatus(RentCarNewVehiclesDB updateCar)
        {
            try
            {
                using (RentCarDatabaseEntities1 fleetEntities = new RentCarDatabaseEntities1())
                {
                    var currentCar = fleetEntities.RentCarNewVehiclesDBs.FirstOrDefault(c => c.LicenseNumber == updateCar.LicenseNumber);

                    currentCar.AvaliableForRent = updateCar.AvaliableForRent;

                    RentCarRentedCar rentedCar = fleetEntities.RentCarRentedCars.FirstOrDefault(c => c.LicenseNumber == updateCar.LicenseNumber);

                    fleetEntities.RentCarRentedCars.Remove(rentedCar);

                    fleetEntities.SaveChanges();
                }
            }
            catch (Exception serverException)
            {
                RentCarServerErrorsLog errorsLog = new RentCarServerErrorsLog();
                errorsLog.ErrorMsg = serverException.ToString();
                errorsLog.Date     = DateTime.Now.ToString();
                using (RentCarDatabaseEntities1 errorsEntities = new RentCarDatabaseEntities1())
                {
                    errorsEntities.RentCarServerErrorsLogs.Add(errorsLog);
                    errorsEntities.SaveChanges();
                }
            }
        }
コード例 #2
0
        public static void AddNewOrderItem()
        {
            try
            {
                // Get the uploaded image from the Files collection
                string pic           = HttpContext.Current.Request.Form["userpic"].Trim();
                string username      = HttpContext.Current.Request.Form["username"].Trim();
                string picture       = HttpContext.Current.Request.Form["picture"].Trim();
                string licensenumber = HttpContext.Current.Request.Form["licensenumber"].Trim();
                string manufacturer  = HttpContext.Current.Request.Form["manufacturer"].Trim();
                string model         = HttpContext.Current.Request.Form["model"].Trim();
                string mileage       = HttpContext.Current.Request.Form["mileage"].Trim();
                string year          = HttpContext.Current.Request.Form["yearOfManufacture"].Trim();
                string branch        = HttpContext.Current.Request.Form["branch"].Trim();
                string daycost       = HttpContext.Current.Request.Form["dailyCost"].Trim();
                string overcost      = HttpContext.Current.Request.Form["overduecost"].Trim();
                string fromdate      = HttpContext.Current.Request.Form["rentfromdate"].Trim();
                string todate        = HttpContext.Current.Request.Form["renttodate"].Trim();
                string returntoBrnch = HttpContext.Current.Request.Form["returntobranch"].Trim();
                string totalcost     = HttpContext.Current.Request.Form["totalcost"].Trim();


                RentCarRentedCar newOrder = new RentCarRentedCar();
                newOrder.UserPicture       = pic;
                newOrder.Username          = username;
                newOrder.Picture           = picture;
                newOrder.LicenseNumber     = licensenumber;
                newOrder.Manufacturer      = manufacturer;
                newOrder.Model             = model;
                newOrder.Mileage           = mileage;
                newOrder.YearOFManufacture = year;
                newOrder.Branch            = branch;
                newOrder.DailyCost         = daycost;
                newOrder.OverdueCost       = overcost;
                newOrder.DateRented        = fromdate;
                newOrder.DateReturned      = todate;
                newOrder.ReturnToBranch    = returntoBrnch;
                newOrder.TotalCost         = totalcost;

                using (RentCarDatabaseEntities1 customersDealsEntities = new RentCarDatabaseEntities1())
                {
                    customersDealsEntities.RentCarRentedCars.Add(newOrder);
                    customersDealsEntities.SaveChanges();
                }
            }
            catch (Exception serverException)
            {
                RentCarServerErrorsLog errorsLog = new RentCarServerErrorsLog();
                errorsLog.ErrorMsg = serverException.ToString();
                errorsLog.Date     = DateTime.Now.ToString();
                using (RentCarDatabaseEntities1 errorsEntities = new RentCarDatabaseEntities1())
                {
                    errorsEntities.RentCarServerErrorsLogs.Add(errorsLog);
                    errorsEntities.SaveChanges();
                }
            }
        }