Beispiel #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;
                }
            }
        }
Beispiel #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;
                }
            }
        }
Beispiel #3
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;
                }
            }
        }
Beispiel #4
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;
                }
            }
        }
Beispiel #5
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;
                }
            }
        }
Beispiel #6
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;
                }
            }
        }