public PhotoEntity Add(PhotoEntity t) { photo photo = new photo(); Mapper.Map(t, photo); using (this.mEntities = new photoshareEntities()) { this.mEntities.photos.AddObject(photo); if (t.Favorite) { favoritephoto favorite = new favoritephoto(); Mapper.Map(photo, favorite); this.mEntities.favoritephotos.AddObject(favorite); } this.mEntities.SaveChanges(); } return t; }
public void Update(PhotoEntity t) { using (this.mEntities = new photoshareEntities()) { photo current = this.mEntities.photos.FirstOrDefault(x => x.Id == t.Id); this.mEntities.photos.Attach(current); photo photo = Mapper.Map<photo>(t); this.mEntities.photos.ApplyCurrentValues(photo); if (t.Favorite) { favoritephoto favorite = new favoritephoto(); favorite.Date = DateTime.UtcNow; Mapper.Map(photo, favorite); this.mEntities.favoritephotos.AddObject(favorite); } else { var favorite = this.mEntities.favoritephotos.FirstOrDefault(x => x.PhotoId == t.Id && x.Owner == t.Owner); this.mEntities.favoritephotos.DeleteObject(favorite); } this.mEntities.SaveChanges(); } }
/// <summary> /// Create a new favoritephoto object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="photoId">Initial value of the PhotoId property.</param> /// <param name="owner">Initial value of the Owner property.</param> public static favoritephoto Createfavoritephoto(global::System.Guid id, global::System.Guid photoId, global::System.Guid owner) { favoritephoto favoritephoto = new favoritephoto(); favoritephoto.Id = id; favoritephoto.PhotoId = photoId; favoritephoto.Owner = owner; return favoritephoto; }
/// <summary> /// Deprecated Method for adding a new object to the favoritephotos EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTofavoritephotos(favoritephoto favoritephoto) { base.AddObject("favoritephotos", favoritephoto); }