Ejemplo n.º 1
0
        public static void UpdateBranchDetails(RentCarBranch updatebranch)
        {
            try
            {
                using (RentCarDatabaseEntities1 branchEntities = new RentCarDatabaseEntities1())
                {
                    var currentBranch = branchEntities.RentCarBranches.FirstOrDefault(c => c.id == updatebranch.id);

                    currentBranch.branches  = updatebranch.branches;
                    currentBranch.address   = updatebranch.address;
                    currentBranch.latitude  = updatebranch.latitude;
                    currentBranch.longitude = updatebranch.longitude;
                    currentBranch.status    = updatebranch.status;
                    branchEntities.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();
                }
            }
        }
Ejemplo n.º 2
0
        public static List <string> GetBranchesLocations()
        {
            try
            {
                using (RentCarDatabaseEntities1 branchEntities = new RentCarDatabaseEntities1())
                {
                    var branchName = branchEntities.Database.SqlQuery <string>("Select branches from RentCarBranches").ToList();

                    var branchLat = branchEntities.Database.SqlQuery <string>("Select latitude from RentCarBranches").ToList();

                    var branchLng = branchEntities.Database.SqlQuery <string>("Select longitude from RentCarBranches").ToList();

                    List <string> rentcarBranches = new List <string>();

                    for (int i = 0; i < branchName.Count; i++)
                    {
                        rentcarBranches.Add(branchName[i] + ":" + branchLat[i] + ":" + branchLng[i]);
                    }

                    return(rentcarBranches);
                }
            }
            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();
                }
                return(null);
            }
        }
        public static void UpdateUserpassword(string username, string password)
        {
            try
            {
                using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
                {
                    var currentUser = userEntities.RentCarUserDBs.FirstOrDefault(c => c.UserName == username);

                    if (currentUser != null)
                    {
                        currentUser.Password = password;
                        userEntities.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();
                }
            }
        }
Ejemplo n.º 4
0
 public static string Login(string username, string password)
 {
     try
     {
         if (UserLoginSecurity.LogIn(username, password))
         {
             DateTime epoch       = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
             long     ms          = (long)(DateTime.UtcNow - epoch).TotalMilliseconds;
             string   tokenString = username + ":" + ms;
             return(Encryptor.Encrypt(tokenString));
         }
         return("error");
     }
     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();
         }
         return("error");
     }
 }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 6
0
        public static List <RentCarRentedCar> GetRentedCarsByLisnumber(string licensenumber)
        {
            try
            {
                using (RentCarDatabaseEntities1 fleetEntities = new RentCarDatabaseEntities1())
                {
                    var CarsForRent =
                        fleetEntities.RentCarRentedCars.SqlQuery(
                            "Select * from RentCarRentedCars Where LicenseNumber = '" + licensenumber + "'").ToList();

                    List <RentCarRentedCar> avaliableCars = new List <RentCarRentedCar>();

                    foreach (var cardata in CarsForRent)
                    {
                        avaliableCars.Add(cardata);
                    }
                    return(avaliableCars);
                }
            }
            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();
                }
                return(null);
            }
        }
        public static void UpdateUser(RentCarUserDB updateuser)
        {
            try
            {
                using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
                {
                    var currentUser = userEntities.RentCarUserDBs.FirstOrDefault(c => c.Id == updateuser.Id);

                    currentUser.Picture   = updateuser.Picture;
                    currentUser.FullName  = updateuser.FullName;
                    currentUser.UserName  = updateuser.UserName;
                    currentUser.BirthDate = updateuser.BirthDate;
                    currentUser.Gender    = updateuser.Gender;
                    currentUser.Password  = updateuser.Password;
                    currentUser.Email     = updateuser.Email;
                    currentUser.IsAdmin   = updateuser.IsAdmin;
                    userEntities.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();
                }
            }
        }
Ejemplo n.º 8
0
 public static void UpdateContactDetails(RentCarContact updateContact)
 {
     try
     {
         using (RentCarDatabaseEntities1 contactEntities = new RentCarDatabaseEntities1())
         {
             var currentContact = contactEntities.RentCarContacts.FirstOrDefault(c => c.Id == updateContact.Id);
             currentContact.Department  = updateContact.Department;
             currentContact.ContactName = updateContact.ContactName;
             currentContact.Tel         = updateContact.Tel;
             currentContact.Fax         = updateContact.Fax;
             currentContact.Mail        = updateContact.Mail;
             contactEntities.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();
         }
     }
 }
Ejemplo n.º 9
0
        public static void AddOrderToHistory()
        {
            try
            {
                // Get the uploaded image from the Files collection

                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 actualreturndate = HttpContext.Current.Request.Form["actualreturndate"].Trim();
                string returntoBranch   = HttpContext.Current.Request.Form["returntobrnch"].Trim();
                string finaltotalcost   = HttpContext.Current.Request.Form["finaltotalcost"].Trim();


                RentCarUsersRentHistory newOrderHistory = new RentCarUsersRentHistory();
                newOrderHistory.Username          = username;
                newOrderHistory.Picture           = picture;
                newOrderHistory.LicenseNumber     = licensenumber;
                newOrderHistory.Manufacturer      = manufacturer;
                newOrderHistory.Model             = model;
                newOrderHistory.Mileage           = mileage;
                newOrderHistory.YearOfManufacture = year;
                newOrderHistory.Branch            = branch;
                newOrderHistory.DailyCost         = daycost;
                newOrderHistory.OverdueCost       = overcost;
                newOrderHistory.FromRentedDate    = fromdate;
                newOrderHistory.ToRentedDate      = todate;
                newOrderHistory.ActualReturnDate  = actualreturndate;
                newOrderHistory.ReturnedToBranch  = returntoBranch;
                newOrderHistory.FinalTotalCost    = finaltotalcost;



                using (RentCarDatabaseEntities1 customersHistoryEntities = new RentCarDatabaseEntities1())
                {
                    customersHistoryEntities.RentCarUsersRentHistories.Add(newOrderHistory);
                    customersHistoryEntities.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();
                }
            }
        }
        public static List <RentCarUsersRentHistory> OrdersHistory(string username)
        {
            try
            {
                using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
                {
                    var usersHistory =
                        userEntities.RentCarUsersRentHistories.SqlQuery(
                            "Select * from RentCarUsersRentHistory Where Username = '******'");

                    List <RentCarUsersRentHistory> historyList = new List <RentCarUsersRentHistory>();

                    foreach (var userhistory in usersHistory)
                    {
                        historyList.Add(userhistory);
                    }
                    return(historyList);
                }
            }
            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();
                }
                return(null);
            }
        }
        public static List <RentCarNewVehiclesDB> GetOnlyAvaliableCars()
        {
            try
            {
                using (RentCarDatabaseEntities1 fleetEntities = new RentCarDatabaseEntities1())
                {
                    var carsForRent =
                        fleetEntities.RentCarNewVehiclesDBs.SqlQuery(
                            "Select * from RentCarNewVehiclesDB Where AvaliableForRent = 'Avaliable'").ToList();

                    List <RentCarNewVehiclesDB> avaliableCars = new List <RentCarNewVehiclesDB>();

                    foreach (var cardata in carsForRent)
                    {
                        avaliableCars.Add(cardata);
                    }
                    return(avaliableCars);
                }
            }
            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();
                }
                return(null);
            }
        }
 public static bool LogIn(string username, string password)
 {
     using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
     {
         return(userEntities.RentCarUserDBs.Any(user => user.UserName.Equals(username,
                                                                             StringComparison.OrdinalIgnoreCase) &&
                                                user.Password == password));
     }
 }//show user by its id
        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();
                }
            }
        }
        public static List <string> DetailByPicture(string pic)
        {
            try
            {
                using (RentCarDatabaseEntities1 fleetEntities = new RentCarDatabaseEntities1())
                {
                    var picture =
                        fleetEntities.Database.SqlQuery <string>("Select Picture from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    var lisnum =
                        fleetEntities.Database.SqlQuery <string>("Select LicenseNumber from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    var manufac =
                        fleetEntities.Database.SqlQuery <string>("Select Manufacturer from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    var model =
                        fleetEntities.Database.SqlQuery <string>("Select Model from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    var mileage =
                        fleetEntities.Database.SqlQuery <string>("Select Mileage from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    var year =
                        fleetEntities.Database.SqlQuery <string>("Select YearOfManufacture from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    var branch =
                        fleetEntities.Database.SqlQuery <string>("Select Branch from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    var dailycost =
                        fleetEntities.Database.SqlQuery <string>("Select DailyCost from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    var overcost =
                        fleetEntities.Database.SqlQuery <string>("Select OverdueCost from RentCarNewVehiclesDB where Picture = '" + pic + "'").ToList();
                    List <string> lastViewedCarDetail = new List <string>();


                    lastViewedCarDetail.Add(picture[0]);
                    lastViewedCarDetail.Add(lisnum[0]);
                    lastViewedCarDetail.Add(manufac[0]);
                    lastViewedCarDetail.Add(model[0]);
                    lastViewedCarDetail.Add(mileage[0]);
                    lastViewedCarDetail.Add(year[0]);
                    lastViewedCarDetail.Add(branch[0]);
                    lastViewedCarDetail.Add(dailycost[0]);
                    lastViewedCarDetail.Add(overcost[0]);

                    return(lastViewedCarDetail);
                }
            }
            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();
                }
                return(null);
            }
        }
        public static List <string> IsUserExist(string username, string email)
        {
            try
            {
                using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
                {
                    string usernameChecked = "usernameValid";
                    string mailChecked     = "mailValid";

                    var userNames = userEntities.RentCarUserDBs.SqlQuery("select * from RentCarUserDB").ToList();

                    List <string> usersExistanceList = new List <string>();

                    foreach (var name in userNames)
                    {
                        if (name.UserName.Trim() == username.Trim())
                        {
                            usernameChecked = "usernameExist";
                        }
                    }

                    foreach (var mail in userNames)
                    {
                        if (mail.Email.Trim() == email.Trim())
                        {
                            mailChecked = "mailExist";
                        }
                    }

                    usersExistanceList.Add(usernameChecked);
                    usersExistanceList.Add(mailChecked);
                    return(usersExistanceList);
                }
            }
            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();
                }
                return(null);
            }
        }
Ejemplo n.º 16
0
        public static List <string> TokenValidation(string token)
        {
            try
            {
                if (token != "")
                {
                    string   decryptedToken        = Encryptor.Decrypt(token);
                    string[] usernamePasswordArray = decryptedToken.Split(':');
                    string   username = usernamePasswordArray[0];
                    string   date     = usernamePasswordArray[1];

                    using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
                    {
                        var decryptedUsername = userEntities.Database.SqlQuery <string>(
                            "SELECT Username FROM RentcarUserDB WHERE Username = '******'").ToList();

                        var decryptedPicture = userEntities.Database.SqlQuery <string>(
                            "SELECT Picture FROM RentcarUserDB WHERE Username = '******'").ToList();

                        var isadmin = userEntities.Database.SqlQuery <string>(
                            "SELECT IsAdmin FROM RentcarUserDB WHERE Username = '******'").ToList();

                        List <string> s = new List <string>();
                        s.Add(decryptedUsername[0].Trim());
                        s.Add(decryptedPicture[0].Trim());
                        s.Add(date);
                        s.Add(isadmin[0].Trim());
                        return(s);
                    }
                }
                return(null);
            }
            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();
                }
                return(null);
            }
        }
 public static void SendFeedback(string from, string to, string subject, string content)
 {
     try
     {
         MailMessage mail = new MailMessage();
         mail.To.Add(to);
         mail.From            = new MailAddress(from, subject, System.Text.Encoding.UTF8);
         mail.Subject         = subject;
         mail.SubjectEncoding = System.Text.Encoding.UTF8;
         mail.Body            = content;
         mail.BodyEncoding    = System.Text.Encoding.UTF8;
         mail.IsBodyHtml      = true;
         mail.Priority        = MailPriority.High;
         SmtpClient client = new SmtpClient();
         client.Credentials = new NetworkCredential("*****@*****.**", "namal2011");
         client.Port        = 587;
         client.Host        = "smtp.gmail.com";
         client.EnableSsl   = true;
         try
         {
             client.Send(mail);
         }
         catch (Exception ex)
         {
             Exception ex2          = ex;
             string    errorMessage = string.Empty;
             while (ex2 != null)
             {
                 errorMessage += ex2.ToString();
                 ex2           = ex2.InnerException;
             }
         }
     }
     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();
         }
     }
 }
Ejemplo n.º 18
0
        public static List <string> GetSearchedBranches(string brnch)
        {
            try
            {
                using (RentCarDatabaseEntities1 branchEntities = new RentCarDatabaseEntities1())
                {
                    var branchesName = branchEntities.Database.SqlQuery <string>("select branches from rentcarbranches where branches like  '%" + brnch + "%'").ToList();


                    var branchesLat = branchEntities.Database.SqlQuery <string>("select latitude from rentcarbranches where branches like  '%" + brnch + "%'").ToList();


                    var           branchesLng   = branchEntities.Database.SqlQuery <string>("select longitude from rentcarbranches where branches like  '%" + brnch + "%'").ToList();
                    List <string> branchFounded = new List <string>();

                    try
                    {
                        branchFounded.Add(branchesName[0].Trim());
                        branchFounded.Add(branchesLat[0].Trim());
                        branchFounded.Add(branchesLng[0].Trim());
                        return(branchFounded);
                    }
                    catch (Exception e)
                    {
                        branchFounded.Add("branchnotFound");
                        return(branchFounded);
                    }
                }
            }
            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();
                }
                return(null);
            }
        }
 public static IEnumerable <RentCarServerErrorsLog> GetErrorsLog()
 {
     try
     {
         using (RentCarDatabaseEntities1 serverErrorsEntities = new RentCarDatabaseEntities1())
         {
             return(serverErrorsEntities.RentCarServerErrorsLogs.ToList());
         }
     }
     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();
         }
         return(null);
     }
 }
Ejemplo n.º 20
0
 public static void AddContact(RentCarContact newContact)
 {
     try
     {
         using (RentCarDatabaseEntities1 contactEntities = new RentCarDatabaseEntities1())
         {
             contactEntities.RentCarContacts.Add(newContact);
             contactEntities.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();
         }
     }
 }
Ejemplo n.º 21
0
 public static void AddBranch(RentCarBranch newbranch)
 {
     try
     {
         using (RentCarDatabaseEntities1 branchEntities = new RentCarDatabaseEntities1())
         {
             branchEntities.RentCarBranches.Add(newbranch);
             branchEntities.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();
         }
     }
 }
        public static void DeleteUser(int Id)
        {
            try
            {
                using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
                {
                    RentCarUserDB usr = userEntities.RentCarUserDBs.FirstOrDefault(c => c.Id == Id);

                    string rootFolderPath = usr.Picture;

                    string[] filesToDelete = rootFolderPath.Split('\\');//rootFolderPath.Substring(14, rootFolderPath.Length - 14).Trim();

                    if (filesToDelete[3] != "default.jpg")
                    {
                        string   directoryName = Path.GetDirectoryName(rootFolderPath);
                        string[] fileList      = Directory.GetFiles(directoryName,
                                                                    filesToDelete[3]);
                        foreach (string file in fileList)
                        {
                            System.Diagnostics.Debug.WriteLine(file + "will be deleted");
                            File.Delete(file);
                        }
                    }
                    userEntities.RentCarUserDBs.Remove(usr);
                    userEntities.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();
                }
            }
        }
 public static RentCarUserDB Get(int id)
 {
     try
     {
         using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
         {
             return(userEntities.RentCarUserDBs.FirstOrDefault(c => c.Id == id));
         }
     }
     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();
         }
         return(null);
     }
 }
        public static void DeleteCarByLicenceNumber(int id)
        {
            try
            {
                using (RentCarDatabaseEntities1 fleetEntities = new RentCarDatabaseEntities1())
                {
                    RentCarNewVehiclesDB FCar = fleetEntities.RentCarNewVehiclesDBs.FirstOrDefault(c => c.Id == id);

                    string   rootFolderPath = FCar.Picture;
                    string[] filesToDelete  = rootFolderPath.Split('\\');//rootFolderPath.Substring(19, rootFolderPath.Length - 21).Trim();
                    if (filesToDelete[3] != "defaultcar.png")
                    {
                        string   directoryName = Path.GetDirectoryName(rootFolderPath);
                        string[] fileList      = System.IO.Directory.GetFiles(directoryName,
                                                                              filesToDelete[3]);
                        foreach (string file in fileList)
                        {
                            System.Diagnostics.Debug.WriteLine(file + "will be deleted");
                            File.Delete(file);
                        }
                    }

                    fleetEntities.RentCarNewVehiclesDBs.Remove(FCar);
                    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();
                }
            }
        }
Ejemplo n.º 25
0
 public static void DeleteContactById(int id)
 {
     try
     {
         using (RentCarDatabaseEntities1 contactEntities = new RentCarDatabaseEntities1())
         {
             RentCarContact cont = contactEntities.RentCarContacts.FirstOrDefault(c => c.Id == id);
             contactEntities.RentCarContacts.Remove(cont);
             contactEntities.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();
         }
     }
 }
Ejemplo n.º 26
0
 public static void DeleteBranchByName(int Id)
 {
     try
     {
         using (RentCarDatabaseEntities1 branchEntities = new RentCarDatabaseEntities1())
         {
             RentCarBranch brc = branchEntities.RentCarBranches.FirstOrDefault(c => c.id == Id);
             branchEntities.RentCarBranches.Remove(brc);
             branchEntities.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();
         }
     }
 }
Ejemplo n.º 27
0
        public static List <string> GetBranchesNameByLocations(string lat, string lng)
        {
            try
            {
                using (RentCarDatabaseEntities1 branchEntities = new RentCarDatabaseEntities1())
                {
                    try
                    {
                        var brname1 = branchEntities.Database.SqlQuery <string>("Select branches from RentCarBranches where latitude = " + lat).ToList();
                        var brname2 = branchEntities.Database.SqlQuery <string>("Select branches from RentCarBranches where longitude = " + lng).ToList();

                        List <string> bname = new List <string>();
                        if (brname1.ToString() == brname2.ToString())
                        {
                            bname.Add(brname1[0]);
                        }
                        return(bname);
                    }
                    catch (Exception e)
                    {
                        return(null);
                    }
                }
            }
            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();
                }
                return(null);
            }
        }
        public static void UpdateCarDetails(RentCarNewVehiclesDB updateCar)
        {
            try
            {
                using (RentCarDatabaseEntities1 fleetEntities = new RentCarDatabaseEntities1())
                {
                    var currentCar = fleetEntities.RentCarNewVehiclesDBs.FirstOrDefault(c => c.Id == updateCar.Id);

                    currentCar.Picture           = updateCar.Picture;
                    currentCar.LicenseNumber     = updateCar.LicenseNumber;
                    currentCar.Manufacturer      = updateCar.Manufacturer;
                    currentCar.Model             = updateCar.Model;
                    currentCar.Gear              = updateCar.Gear;
                    currentCar.Mileage           = updateCar.Mileage;
                    currentCar.YearOfManufacture = updateCar.YearOfManufacture;
                    currentCar.ProperForRent     = updateCar.ProperForRent;
                    currentCar.AvaliableForRent  = updateCar.AvaliableForRent;
                    currentCar.Branch            = updateCar.Branch;
                    currentCar.DailyCost         = updateCar.DailyCost;
                    currentCar.OverdueCost       = updateCar.OverdueCost;
                    currentCar.Category          = updateCar.Category;
                    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();
                }
            }
        }
        public static void AddNewUser()
        {
            try
            {
                // Get the uploaded image from the Files collection
                var      httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"];
                string   fullname       = HttpContext.Current.Request.Form["fullname"].Trim();
                string   userName       = HttpContext.Current.Request.Form["userName"].Trim();
                DateTime birthdate      = Convert.ToDateTime(HttpContext.Current.Request.Form["birthdate"]);
                string   gender         = HttpContext.Current.Request.Form["gender"];
                string   password       = HttpContext.Current.Request.Form["password"].Trim();
                string   email          = HttpContext.Current.Request.Form["email"].Trim();
                string   isadmin        = "false";
                string   picture        = null;


                if (httpPostedFile != null)
                {
                    // Get the complete file path
                    var fileSavePath = HttpContext.Current.Server.MapPath(@"~\usersimg\");

                    // Validate the uploaded image(optional)
                    if (!Directory.Exists(fileSavePath))
                    {
                        Directory.CreateDirectory(fileSavePath);
                    }

                    // Save the uploaded file to "UploadedFiles" folder
                    File.SetAttributes(fileSavePath, FileAttributes.Normal);
                    picture = HttpContext.Current.Server.MapPath(@"~\usersimg\" + userName + Path.GetExtension(httpPostedFile.FileName));
                    FileStream fileStream = File.Create(picture,
                                                        (int)httpPostedFile.InputStream.Length);
                    // Initialize the bytes array with the stream length and then fill it with data
                    byte[] bytesInStream = new byte[httpPostedFile.InputStream.Length];
                    httpPostedFile.InputStream.Read(bytesInStream, 0, bytesInStream.Length);
                    // Use write method to write to the file specified above
                    fileStream.Write(bytesInStream, 0, bytesInStream.Length);

                    fileStream.Dispose();
                }
                RentCarUserDB newuser = new RentCarUserDB();
                newuser.UserName  = userName;
                newuser.FullName  = fullname;
                newuser.BirthDate = birthdate;
                newuser.Gender    = gender;
                newuser.Password  = password;
                newuser.Email     = email;
                newuser.IsAdmin   = isadmin;
                if (picture != null)
                {
                    string[] serverSplttedPath = picture.Split('\\');

                    string userpic = '\\' + serverSplttedPath [5] + '\\' + serverSplttedPath[6] + '\\' + '\\' + serverSplttedPath[7];

                    newuser.Picture = userpic;
                }
                else
                {
                    newuser.Picture = "\\usersimg\\default.jpg";
                }

                using (RentCarDatabaseEntities1 userEntities = new RentCarDatabaseEntities1())
                {
                    userEntities.RentCarUserDBs.Add(newuser);
                    userEntities.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();
                }
            }
        }
        public static void AddNewCar()
        {
            try
            {
                // Get the uploaded image from the Files collection
                var    httpPostedFile    = HttpContext.Current.Request.Files["UploadedImage"];
                string licensenumber     = HttpContext.Current.Request.Form["licensenumber"].Trim();
                string manufacturer      = HttpContext.Current.Request.Form["manufacturer"].Trim();
                string model             = HttpContext.Current.Request.Form["model"];
                string gear              = HttpContext.Current.Request.Form["gear"];
                string mileage           = HttpContext.Current.Request.Form["mileage"].Trim();
                string yearOfManufacture = HttpContext.Current.Request.Form["yearOfManufacture"].Trim();
                string properForRent     = HttpContext.Current.Request.Form["properForRent"].Trim();
                string avaliableForRent  = HttpContext.Current.Request.Form["avaliableForRent"].Trim();
                string branch            = HttpContext.Current.Request.Form["branch"].Trim();
                string dailyCost         = HttpContext.Current.Request.Form["dailyCost"].Trim();
                string overdueCost       = HttpContext.Current.Request.Form["overdueCost"].Trim();
                string category          = HttpContext.Current.Request.Form["category"].Trim();
                string picture           = null;


                if (httpPostedFile != null)
                {
                    // Get the complete file path
                    var fileSavePath = HttpContext.Current.Server.MapPath(@"~\vehiclesFleet\");


                    // Validate the uploaded image(optional)
                    if (!Directory.Exists(fileSavePath))
                    {
                        Directory.CreateDirectory(fileSavePath);
                    }

                    // Save the uploaded file to "UploadedFiles" folder
                    File.SetAttributes(fileSavePath, FileAttributes.Normal);
                    picture = HttpContext.Current.Server.MapPath(@"~\vehiclesFleet\" + licensenumber + Path.GetExtension(httpPostedFile.FileName));
                    FileStream fileStream = File.Create(picture,
                                                        (int)httpPostedFile.InputStream.Length);

                    // Initialize the bytes array with the stream length and then fill it with data
                    byte[] bytesInStream = new byte[httpPostedFile.InputStream.Length];
                    httpPostedFile.InputStream.Read(bytesInStream, 0, bytesInStream.Length);
                    // Use write method to write to the file specified above
                    fileStream.Write(bytesInStream, 0, bytesInStream.Length);

                    fileStream.Dispose();
                }
                RentCarNewVehiclesDB newCar = new RentCarNewVehiclesDB();
                newCar.LicenseNumber     = licensenumber;
                newCar.Manufacturer      = manufacturer;
                newCar.Model             = model;
                newCar.Gear              = gear;
                newCar.Mileage           = mileage;
                newCar.YearOfManufacture = yearOfManufacture;
                newCar.ProperForRent     = properForRent;
                newCar.AvaliableForRent  = avaliableForRent;
                newCar.Branch            = branch;
                newCar.DailyCost         = dailyCost;
                newCar.OverdueCost       = overdueCost;
                newCar.Category          = category;

                if (picture != null)
                {
                    string[] serverSplttedPath = picture.Split('\\');

                    string vehiclepic = '\\' + serverSplttedPath[5] + '\\' + serverSplttedPath[6] + '\\' + '\\' + serverSplttedPath[7];
                    newCar.Picture = vehiclepic;
                }
                else
                {
                    newCar.Picture = "\\vehiclesFleet\\defaultcar.png";
                }

                using (RentCarDatabaseEntities1 fleetEntities = new RentCarDatabaseEntities1())
                {
                    fleetEntities.RentCarNewVehiclesDBs.Add(newCar);
                    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();
                }
            }
        }