public Photo Add(Photo item, string login) { if (item == null) { throw new ArgumentNullException("item"); } var profiles = _personRepository.GetAll(); PersonProfile dbEntry = profiles.SingleOrDefault(x => x.Login == login); if (dbEntry != null) { if (item.IsProfile) { var photos = _repo.Photos.GetAll(); photos.Where(x => x.IsProfile && x.PersonProfile.PersonProfileId == dbEntry.PersonProfileId) .ForEach(x => x.IsProfile = false); foreach (var photo in photos) { _repo.Photos.Update(photo); } _repo.Commit(); } dbEntry.Photos.Add(item); _personRepository.Update(dbEntry); } return(item); }
public PersonProfile Add(PersonProfile item) { if (item == null) { throw new ArgumentNullException("item"); } _repo.PersonProfiles.Add(item); _repo.Commit(); return(item); }
public bool SendMessage(Message message, string login) { message.Created = DateTime.UtcNow; PersonProfile sender = _repo.PersonProfiles.GetAll().SingleOrDefault(x => x.Login == login); if (sender == null) { return(false); } PersonProfile receiver = _repo.PersonProfiles.GetById(message.SecPersonProfileId); if (receiver == null) { return(false); } //sprawdzam czy mial juz jakis kontakt z denatem PersonProfileMessage messages = _repo.PersonProfileMessages.GetAll() .SingleOrDefault( x => x.PersonProfile.PersonProfileId == sender.PersonProfileId && x.SecPersonProfile.PersonProfileId == receiver.PersonProfileId || x.PersonProfile.PersonProfileId == receiver.PersonProfileId && x.SecPersonProfile.PersonProfileId == sender.PersonProfileId); if (messages == null) // ta dluzsza opcja { var newContact = new PersonProfileMessage { Messages = new Collection <Message>(), PersonProfile = sender, SecPersonProfile = receiver, PersonProfileId = sender.PersonProfileId, SecPersonProfileId = receiver.PersonProfileId }; newContact.Messages.Add(message); _repo.Messages.Add(message); _repo.PersonProfileMessages.Add(newContact); _repo.Commit(); return(true); } _repo.Messages.Add(message); messages.Messages.Add(message); _repo.Commit(); return(true); }
public Location Add(Location item, string login) { if (item == null) { throw new ArgumentNullException("item"); } var profiles = _personRepository.GetAll(); PersonProfile dbEntry = profiles.SingleOrDefault(x => x.Login == login); if (dbEntry != null) { if (item.IsHomeTown) { var locations = _repo.Locations.GetAll(); locations.Where(x => x.IsHomeTown && x.PersonProfile.PersonProfileId == dbEntry.PersonProfileId) .ForEach(x => x.IsHomeTown = false); _repo.Commit(); } if (item.IsCurrentLocation) { var locations = _repo.Locations.GetAll(); locations.Where( x => x.IsCurrentLocation && x.PersonProfile.PersonProfileId == dbEntry.PersonProfileId) .ForEach(x => x.IsCurrentLocation = false); _repo.Commit(); } dbEntry.Location.Add(item); _personRepository.Update(dbEntry); } return(item); }
public GlobalMovie Add(GlobalMovie item, string login) { if (item == null) { throw new ArgumentNullException("item"); } var dbEntry = _repo.PersonProfiles.GetAll().SingleOrDefault(x => x.Login == login); if (dbEntry != null) { GlobalMovie antiDoubleGlobalMovie = _repo.GlobalMovies.GetAll().SingleOrDefault(x => x.Title == item.Title); if (antiDoubleGlobalMovie == null) { var newDbEntry = new GlobalMovieLike(item, dbEntry); dbEntry.GlobalMovieLikes.Add(newDbEntry); _repo.PersonProfiles.Update(dbEntry); _repo.Commit(); return(new GlobalMovie()); } return(null); } return(item); }