Ejemplo n.º 1
0
        internal static void AddAutoPhoto(string autoNumber, string photoFileName)
        {
            using (CarsEntity autorentEntityContext = new CarsEntity())
            {
                try
                {
                   AutoPhoto autoPhoto = new AutoPhoto
                    {
                        AutoNumber = autoNumber,
                        DoDate = DateTime.UtcNow,
                        PhotoFileName = photoFileName
                    };

                    var queryAuto = (from auto in autorentEntityContext.Autoes where auto.Number == autoNumber select auto).FirstOrDefault();

                    if (!ReferenceEquals(queryAuto, default(Models.Auto.Auto)))
                    {
                        queryAuto.AutoPhotos.Add(autoPhoto);
                        autorentEntityContext.SaveChanges();
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete model
        /// </summary>
        /// <param name="ID">Model Id</param>
        public static void DeleteModel(Guid ID)
        {
            using (CarsEntity autorentEntity = new CarsEntity())
            {
                try
                {
                    var query = (from am in autorentEntity.AutoModels where am.Id == ID select am).FirstOrDefault();

                    autorentEntity.DeleteObject(query);
                    autorentEntity.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 3
0
        public static int CountModels()
        {
            int count = 0;

            using (CarsEntity autorentEntityContext = new CarsEntity())
            {
                try
                {
                    count = (from models in autorentEntityContext.AutoModels select models).Count();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return count;
        }
Ejemplo n.º 4
0
        public static void DeleteAuto(string carNumber)
        {
            using (CarsEntity autorentEntity = new CarsEntity())
            {
                try
                {
                    var queryAuto = (from auto in autorentEntity.Autoes where auto.Number == carNumber select auto).FirstOrDefault();
                    var queryPhotos = (from photos in autorentEntity.AutoPhotos where photos.AutoNumber == queryAuto.Number select photos);

                    autorentEntity.DeleteObject(queryPhotos);
                    autorentEntity.DeleteObject(queryAuto);
                    autorentEntity.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 5
0
        public static void AddAuto(Auto newAuto)
        {
            using (CarsEntity autorentEntityContext = new CarsEntity())
            {
                try
                {
                    Models.Auto.Auto auto = new Models.Auto.Auto
                    {
                        Number = newAuto.CarNumber,
                        ModelId = newAuto.ModelID,
                        BodyType = (int)newAuto.BodyType,
                        InsuaranceId = newAuto.InsuranceNumber,
                        Year = newAuto.CreationYear,
                        Mileage = newAuto.CurrentMilage,
                        Engine = newAuto.Engine,
                        ColorGroup = newAuto.CarColor,
                        DayRate = newAuto.DayRate,
                        KmRate = newAuto.KmRate,
                        Status = (short)newAuto.Status,
                        Advance = newAuto.Advance
                    };

                    if (!ReferenceEquals(newAuto.PhotoFileName, null))
                    {
                        Models.Auto.AutoPhoto autoPhotos = new AutoPhoto
                        {
                            AutoNumber = newAuto.CarNumber,
                            DoDate = DateTime.UtcNow,
                            PhotoFileName = newAuto.PhotoFileName
                        };

                        auto.AutoPhotos.Add(autoPhotos);
                    }

                    autorentEntityContext.Autoes.AddObject(auto);
                    autorentEntityContext.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add model
        /// </summary>
        public static void AddModel(ModelCar car)
        {
            using (CarsEntity autorentEntityContext = new CarsEntity())
            {
                try
                {
                    Autorent.Models.Auto.AutoModel autoModel = new Autorent.Models.Auto.AutoModel
                    {
                        Id = Guid.NewGuid(),
                        Maker = car.Make,
                        ConceptName = car.ModelAuto,
                        Year = (short)car.Year,
                        Class = ((int)car.ClassAuto).ToString()
                    };

                    autorentEntityContext.AutoModels.AddObject(autoModel);
                    autorentEntityContext.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Return all models
        /// </summary>
        public static IList<ModelCar> GetModels()
        {
            IList<ModelCar> modelCars = new List<ModelCar>();

            using (CarsEntity autorentEntity = new CarsEntity())
            {
                try
                {
                    var query = from am in autorentEntity.AutoModels select am;

                    foreach (var item in query)
                    {
                        ModelCar modelCar = new ModelCar();

                        modelCar.ID = item.Id;
                        modelCar.Make = item.Maker;
                        modelCar.ModelAuto = item.ConceptName;
                        modelCar.Year = (short)item.Year;
                        modelCar.ClassAuto = (e_AutoClass)Convert.ToInt32(item.Class);

                        modelCars.Add(modelCar);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return modelCars;
        }
Ejemplo n.º 8
0
        public static IList<Auto> GetAutos(string field, string descOrAsc, int startIndex, int count)
        {
            IList<Auto> autos = new List<Auto>();

            using (CarsEntity autorentEntityContext = new CarsEntity())
            {
                try
                {
                    var queryAutosJoin = from a in autorentEntityContext.Autoes
                                         join photo in autorentEntityContext.AutoPhotos on a.Number equals photo.AutoNumber
                                         orderby a.DayRate descending
                                         select new { Autos = a, photo.PhotoFileName };

                    foreach (var item in queryAutosJoin)
                    {
                        Auto auto = new Auto();

                        auto.Advance = item.Autos.Advance;
                        auto.BodyType = (e_BodyType)item.Autos.BodyType;
                        auto.CarColor = item.Autos.ColorGroup;
                        auto.CarNumber = item.Autos.Number;
                        auto.CreationYear = item.Autos.Year;
                        auto.CurrentMilage = item.Autos.Mileage;
                        auto.Status = (CurrentStatus)item.Autos.Status;
                        auto.KmRate = item.Autos.KmRate;
                        auto.DayRate = item.Autos.DayRate;
                        auto.Engine = item.Autos.Engine;
                        auto.ModelID = item.Autos.ModelId;
                        auto.PhotoFileName = item.PhotoFileName.FirstOrDefault().ToString();

                        autos.Add(auto);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return autos;
        }
Ejemplo n.º 9
0
        public static void UpdateAuto(string number, string name, Guid modelID, int bodyType, string insuranceID, short year, int milage, int engine, string color, int dayRate, int kmRate, short status, decimal minRate, string photoFileName)
        {
            using (CarsEntity autorentEntityContext = new CarsEntity())
            {
                try
                {
                    Models.Auto.Auto auto = new Models.Auto.Auto
                    {
                        Number = number,
                        Name = name,
                        ModelId = modelID,
                        BodyType = bodyType,
                        InsuaranceId = insuranceID,
                        Year = year,
                        Mileage = milage,
                        Engine = engine,
                        ColorGroup = color,
                        DayRate = dayRate,
                        KmRate = kmRate,
                        Status = status,
                        Advance = minRate
                    };

                    var queryAuto = (from a in autorentEntityContext.Autoes where a.Number == number select a).FirstOrDefault();
                    var queryPhoto = (from p in autorentEntityContext.AutoPhotos where p.AutoNumber == number select p).FirstOrDefault();

                    queryAuto.AutoPhotos.Clear();

                    auto.AutoPhotos.Add(new AutoPhoto
                    {
                        AutoNumber = auto.Number,
                        DoDate = DateTime.UtcNow,
                        PhotoFileName = photoFileName
                    });

                    queryAuto = auto;

                    autorentEntityContext.SaveChanges();
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 10
0
        public static List<string> GetPhotos(string number)
        {
            List<string> photoList = new List<string>();

            using (CarsEntity carsEntity = new CarsEntity())
            {
                try
                {
                    var queryPhoto = from photos in carsEntity.AutoPhotos
                                     where photos.AutoNumber == number
                                     select photos;

                    foreach (var photo in queryPhoto)
                    {
                        photoList.Add(photo.PhotoFileName);
                    }

                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return photoList;
        }
Ejemplo n.º 11
0
        public static Car GetCar(int index)
        {
            Car car = new Car();

            using (CarsEntity carsEntity = new CarsEntity())
            {
                try
                {
                    var queryAutos = from am in carsEntity.AutoModels
                                     join a in carsEntity.Autoes on am.Id equals a.ModelId
                                     join ap in carsEntity.AutoPhotos on a.Number equals ap.AutoNumber
                                     into j
                                     from ap in j.DefaultIfEmpty()
                                     select new
                                     {
                                         am.Maker,
                                         am.ConceptName,
                                         am.Class,
                                         a.Engine,
                                         a.KmRate,
                                         a.DayRate,
                                         a.Status,
                                         a.Number,
                                         a.Year,
                                         a.Mileage,
                                         a.ColorGroup,
                                         a.Description,
                                         ap.PhotoFileName
                                     };

                    var selectedCar = queryAutos.OrderBy(c => c.ConceptName).Skip(index).FirstOrDefault();
                    car.Brand = selectedCar.Maker;
                    car.Model = selectedCar.ConceptName;
                    car.EngineCapacity = selectedCar.Engine;
                    car.Year = selectedCar.Year;
                    car.Mileage = selectedCar.Mileage;
                    car.Number = selectedCar.Number;
                    car.Color = selectedCar.ColorGroup;
                    car.Comments = selectedCar.Description;
                    car.PhotoFileName = selectedCar.PhotoFileName;
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }
            }

            return car;
        }
Ejemplo n.º 12
0
        public static IList<AutoSearch> GetAutos(AutoSearch autoSearch)
        {
            IList<AutoSearch> autos = new List<AutoSearch>();

            if (!string.IsNullOrEmpty(autoSearch.Make) && !string.IsNullOrEmpty(autoSearch.Model))
            {
                using (CarsEntity autorentEntity = new CarsEntity())
                {
                    try
                    {
                        string classAuto = ((int)autoSearch.ClassAuto).ToString();
                        var queryAutos = from am in autorentEntity.AutoModels
                                         join a in autorentEntity.Autoes on am.Id equals a.ModelId
                                         join ap in autorentEntity.AutoPhotos on a.Number equals ap.AutoNumber
                                         into j
                                         from ap in j.DefaultIfEmpty()
                                         where am.Class == classAuto &&
                                         am.Maker == autoSearch.Make &&
                                         am.ConceptName == autoSearch.Model
                                         select new
                                         {
                                             am.Maker,
                                             am.ConceptName,
                                             am.Class,
                                             a.KmRate,
                                             a.DayRate,
                                             a.Status,
                                             a.Number,
                                             ap.PhotoFileName
                                         };
                        string rawQuery = ((System.Data.Objects.ObjectQuery)queryAutos).ToTraceString();

                        foreach (var item in queryAutos)
                        {
                            AutoSearch auto = new AutoSearch();
                            auto.Number = item.Number;
                            auto.Make = item.Maker;
                            auto.Model = item.ConceptName;
                            auto.ClassAuto = (e_AutoClass)Convert.ToInt32(item.Class);
                            auto.PriceKm = item.KmRate;
                            auto.PriceDay = item.DayRate;
                            auto.CurrentStatus = (CurrentStatus)item.Status;
                            auto.Photo = item.PhotoFileName;

                            autos.Add(auto);
                        }
                    }
                    catch (InvalidOperationException ex)
                    {
                        throw ex;
                    }
                }
            }
            return autos;
        }
Ejemplo n.º 13
0
        public static IList<AutoSearch> GetAutos()
        {
            IList<AutoSearch> autos = new List<AutoSearch>();

            using (CarsEntity autorentEntity = new CarsEntity())
            {
                try
                {
                    var queryAutos = from am in autorentEntity.AutoModels
                                     join a in autorentEntity.Autoes on am.Id equals a.ModelId
                                     join ap in autorentEntity.AutoPhotos on a.Number equals ap.AutoNumber
                                     into j
                                     from ap in j.DefaultIfEmpty()
                                     select new
                                     {
                                         am.Maker,
                                         am.ConceptName,
                                         am.Class,
                                         a.KmRate,
                                         a.DayRate,
                                         a.Status,
                                         a.Number,
                                         ap.PhotoFileName
                                     };

                    foreach (var item in queryAutos)
                    {
                        AutoSearch auto = new AutoSearch();
                        auto.Number = item.Number;
                        auto.Make = item.Maker;
                        auto.Model = item.ConceptName;
                        auto.ClassAuto = (e_AutoClass)Convert.ToInt32(item.Class);
                        auto.PriceKm = item.KmRate;
                        auto.PriceDay = item.DayRate;
                        auto.CurrentStatus = (CurrentStatus)item.Status;
                        auto.Photo = item.PhotoFileName;

                        autos.Add(auto);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }

            }
            return autos;
        }
Ejemplo n.º 14
0
        public static IList<Auto> GetAutos(Guid modelID, string carColor, int creationYear, CurrentStatus status)
        {
            IList<Auto> autos = new List<Auto>();

            using (CarsEntity autorentEntityContext = new CarsEntity())
            {
                try
                {
                    var queryAutosJoin = from a in autorentEntityContext.Autoes
                                         join photo in autorentEntityContext.AutoPhotos on a.Number equals photo.AutoNumber
                                         where a.ModelId == modelID &&
                                         a.ColorGroup == carColor &&
                                         a.Year == creationYear &&
                                         a.Status == (short)status
                                         select new { Autos = a, photo.PhotoFileName };

                    foreach (var item in queryAutosJoin)
                    {
                        Auto auto = new Auto();

                        auto.Advance = item.Autos.Advance;
                        auto.BodyType = (e_BodyType)item.Autos.BodyType;
                        auto.CarColor = item.Autos.ColorGroup;
                        auto.CarNumber = item.Autos.Number;
                        auto.CreationYear = item.Autos.Year;
                        auto.CurrentMilage = item.Autos.Mileage;
                        auto.Status = (CurrentStatus)item.Autos.Status;
                        auto.KmRate = item.Autos.KmRate;
                        auto.DayRate = item.Autos.DayRate;
                        auto.Engine = item.Autos.Engine;
                        auto.ModelID = item.Autos.ModelId;
                        auto.PhotoFileName = item.PhotoFileName.FirstOrDefault().ToString();

                        autos.Add(auto);
                    }
                }
                catch (InvalidOperationException ex)
                {

                    throw ex;
                }
            }

            return autos;
        }