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; } } }
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; } } }
/// <summary> /// Create a new AutoPhoto object. /// </summary> /// <param name="autoNumber">Initial value of the AutoNumber property.</param> /// <param name="doDate">Initial value of the DoDate property.</param> /// <param name="photoFileName">Initial value of the PhotoFileName property.</param> public static AutoPhoto CreateAutoPhoto(global::System.String autoNumber, global::System.DateTime doDate, global::System.String photoFileName) { AutoPhoto autoPhoto = new AutoPhoto(); autoPhoto.AutoNumber = autoNumber; autoPhoto.DoDate = doDate; autoPhoto.PhotoFileName = photoFileName; return autoPhoto; }
/// <summary> /// Deprecated Method for adding a new object to the AutoPhotos EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToAutoPhotos(AutoPhoto autoPhoto) { base.AddObject("AutoPhotos", autoPhoto); }