Beispiel #1
0
 public static void newSupply(SupplyDTO Supply)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         Supply d = Casting.SupplyCasting.castToDAL(Supply);
         d.isDone = false;
         d.price  = Supply.price;
         var dd = db.Supplies.Add(d);
         db.SaveChanges();
         dd.supplyU = Supply.supplyU;
         db.SaveChanges();
     }
 }
Beispiel #2
0
 public static DemandDTO newDemand(DemandDTO demand)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         Demand d = Casting.DemandCasting.castToDAL(demand);
         d.isDone = false;
         var dd = db.Demands.Add(d);
         db.SaveChanges();
         dd.interestedId = demand.interestedId;
         db.SaveChanges();
         return(Casting.DemandCasting.castToDTO(dd));
     }
 }
Beispiel #3
0
        public HttpResponseMessage UploadFile(string id)
        {
            var pathToSql = " http://localhost:58516/UploadFiles/";
            var allPath   = "";
            HttpResponseMessage response = new HttpResponseMessage();
            var abc         = Request.Properties.Values;
            var httpRequest = HttpContext.Current.Request;


            foreach (string file in httpRequest.Files)
            {
                pathToSql = " http://localhost:58516/UploadFiles/";
                var postedFile    = httpRequest.Files[file];
                var directoryPath = HttpContext.Current.Server.MapPath("~/UploadFiles/");
                Directory.CreateDirectory(directoryPath + id);
                allPath = directoryPath + id + "/" + postedFile.FileName;
                postedFile.SaveAs(allPath);
                pathToSql += id + "/" + postedFile.FileName;
                using (carLeasingEntities db = new carLeasingEntities())
                {
                    var car = db.Cars.FirstOrDefault(p => p.carId.ToString() == id);

                    car.picture = pathToSql;
                    db.SaveChanges();
                }
            }

            return(response);
        }
Beispiel #4
0
 public static void deleteDemand(int demandId)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         Demand d = db.Demands.FirstOrDefault(p => p.demanedId == demandId);
         db.Demands.Remove(d);
         db.SaveChanges();
     }
 }
Beispiel #5
0
 public static void deleteSupply(int SupplyId)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         Supply d = db.Supplies.FirstOrDefault(p => p.supplyId == SupplyId);
         db.Supplies.Remove(d);
         db.SaveChanges();
     }
 }
Beispiel #6
0
 public static void deleteCar(int carId)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         Car c = db.Cars.FirstOrDefault(y => y.carId == carId);
         db.Cars.Remove(c);
         db.SaveChanges();
     }
 }
Beispiel #7
0
 public static int newCar(CarDTO car)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         Car newCar = Casting.CarCasting.castToDAL(car);
         db.Cars.Add(newCar);
         db.SaveChanges();
         return(db.Cars.FirstOrDefault(p => p.carNum == car.carNum).carId);
     }
 }
Beispiel #8
0
 public static void deleteSupplyByCar(int id)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         var           d = db.Cars.FirstOrDefault(p => p.carId == id);
         Car           n = d;
         List <Supply> s = db.Supplies.Where(p => p.carNum == n.carNum).ToList();
         db.Supplies.RemoveRange(s);
         db.SaveChanges();
     }
 }
Beispiel #9
0
 public static void updateDetails(UserDTO userU)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         var user = db.Users.Where(i => i.userId == userU.userId).FirstOrDefault();
         user.firstName     = userU.firstName;
         user.lastName      = userU.lastName;
         user.email         = userU.email;
         user.password      = userU.password;
         user.insuranceType = userU.insuranceType;
         user.phone         = userU.phone;
         db.SaveChanges();
     }
 }
Beispiel #10
0
 public static void updateDemand(DemandDTO demand)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         var d = db.Demands.FirstOrDefault(p => p.demanedId == demand.demanedId);
         d.fromDate  = demand.fromDate;
         d.fromHour  = demand.fromHour;
         d.Locationx = demand.Locationx;
         d.Locationy = demand.Locationy;
         d.toDate    = demand.toDate;
         d.toHour    = demand.toHour;
         db.SaveChanges();
     }
 }
Beispiel #11
0
 public static void updateSupply(SupplyDTO Supply)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         var s = db.Supplies.FirstOrDefault(p => p.supplyId == Supply.supplyId);
         s.fromDate     = Supply.fromDate;
         s.fromHour     = Supply.fromHour;
         s.carLocationx = Supply.carLocationx;
         s.carLocationy = Supply.carLocationy;
         s.toDate       = Supply.toDate;
         s.toHour       = Supply.toHour;
         db.SaveChanges();
     }
 }
Beispiel #12
0
 public static UserDTO register(UserDTO user)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         var u = db.Users.FirstOrDefault(p => p.password == user.password);
         if (u != null)
         {
             return(null);
         }
         User newUser = Casting.UserCasting.castToDal(user);
         var  uu      = db.Users.Add(newUser);
         db.SaveChanges();
         return(Casting.UserCasting.castToDto(uu));
     }
 }
Beispiel #13
0
 public static void edit(CarDTO car)
 {
     using (carLeasingEntities db = new carLeasingEntities())
     {
         var c = db.Cars.FirstOrDefault(cr => cr.carId == car.carId);
         c.carNum        = car.carNum;
         c.description   = car.description;
         c.carCompany    = car.carCompany;
         c.expiryDate    = car.expiryDate;
         c.file          = car.file;
         c.insuranceType = car.insuranceType;
         c.model         = car.model;
         c.numSeats      = car.numSeats;
         c.trunc         = car.trunc;
         c.picture       = car.picture;
         db.SaveChanges();
     }
 }
        public static bool CreatTransaction(int supplyId, int demanedId, int userId)
        {
            using (carLeasingEntities db = new carLeasingEntities())
            {
                Supply supply = db.Supplies.FirstOrDefault(s => s.supplyId == supplyId);

                if (demanedId == -1)
                {
                    DemandDTO d = new DemandDTO()
                    {
                        fromDate     = supply.fromDate,
                        fromHour     = supply.fromHour,
                        Locationx    = supply.carLocationx,
                        Locationy    = supply.carLocationy,
                        toDate       = supply.toDate,
                        toHour       = supply.toHour,
                        interestedId = userId
                    };
                    d         = DemandsFunction.newDemand(d);
                    demanedId = d.demanedId;
                }

                Demand demaned = db.Demands.FirstOrDefault(d => d.demanedId == demanedId);
                if (supply != null && demaned != null)
                {
                    Transaction t = new Transaction()
                    {
                        demandId = demanedId,
                        supplyId = supplyId,
                    };
                    db.Transactions.Add(t);
                    supply.isDone  = true;
                    demaned.isDone = true;
                    if (supply.fromDate < demaned.fromDate)
                    {
                        Supply s = new Supply()
                        {
                            carNum       = supply.carNum,
                            carLocationx = supply.carLocationx,
                            carLocationy = supply.carLocationy,
                            supplyId     = supply.supplyId,
                            supplyU      = supply.supplyU,
                            fromDate     = supply.fromDate,
                            fromHour     = supply.fromHour,
                            toDate       = demaned.fromDate,
                            toHour       = demaned.toHour,
                            isDone       = false
                        };
                        db.Supplies.Add(s);
                    }
                    if (supply.toDate > demaned.toDate)
                    {
                        Supply s = new Supply()
                        {
                            carNum       = supply.carNum,
                            carLocationx = supply.carLocationx,
                            carLocationy = supply.carLocationy,
                            supplyId     = supply.supplyId,
                            supplyU      = supply.supplyU,
                            fromDate     = demaned.toDate,
                            fromHour     = demaned.toHour,
                            toDate       = supply.toDate,
                            toHour       = supply.toHour,
                            isDone       = false
                        };
                        db.Supplies.Add(s);
                    }
                }
                db.SaveChanges();
                SendEmail(supply);
            }
            return(true);
        }