public GenericRepository <T> GetRepository <T>() where T : class { var result = new GenericRepository <T>(this.contextHandler.Context); result.Attach(this); return(result); }
public bool UpdateProject(Project project) { //Todo: Call the repository method to add and then to save projectRepository.Attach(project); projectRepository.SaveChanges(); return(true); }
public bool editUser(string email, string password, string password2, string firstName, string lastName) { var validation = string.Empty; if (this.IsHavingValidInputs(email, password, password2, firstName, lastName)) { if (!UserEmailExists(email)) { userRepository.Attach(new Model.User() { email = email, password = password, firstName = firstName, lastName = lastName, userId = Guid.NewGuid() }); userRepository.SaveChanges(); return(true); } else { return(false); } } else { ValidationSummary.Add(validation); return(false); } }
private void UpdateMultiReference(Connection connection, BaseEntity entity, PropertyInfo targetProperty, List <Guid> referencedIds, ICollection <U> referencedEntities) { GenericRepository genericRepository = new GenericRepository(connection); IList currentReferencedEntities = CollectReferencedEntities(connection, targetProperty, referencedIds); ICollection <U> targetPropertyValue = (ICollection <U>)targetProperty.GetValue(entity); targetPropertyValue.Clear(); genericRepository.Attach(entity.GetType(), entity); foreach (U currentReferencedEntity in currentReferencedEntities) { genericRepository.Attach <U>(currentReferencedEntity); } targetPropertyValue.Clear(); foreach (U currentReferencedEntity in currentReferencedEntities) { targetPropertyValue.Add(currentReferencedEntity); } }
public void ThrowArgumentNullException_When_PassedNull() { var contextMock = new Mock <TwitterContext>(); var tweetsDbSetMock = new Mock <DbSet <Tweet> >(); contextMock.Setup(x => x.Set <Tweet>()) .Returns(tweetsDbSetMock.Object); var tweetRepository = new GenericRepository <Tweet, string>(contextMock.Object); Assert.That(() => tweetRepository.Attach(null), Throws.ArgumentNullException); }
public bool UpdateAddress(string country, string city, Int32 postalCode, string streetAddress, string phone) { var validation = string.Empty; if (this.IsHavingValidInputs(country, city, postalCode, streetAddress, phone)) { //Todo: Call the repository method to add and then to save addressRepository.Attach(new Model.Address() { country = country, city = city, postalCode = postalCode, streetAddress = streetAddress, phone = phone }); addressRepository.SaveChanges(); return(true); } else { ValidationSummary.Add(validation); return(false); } }
public bool UpdateAvailibility(Guid userId, Guid skillId, DateTime from, DateTime to) { var validation = string.Empty; if (this.IsHavingValidInputs(userId, skillId, from, to)) { //Todo: Call the repository method to add and then to save availibilityRepository.Attach(new Model.Availibility() { userId = userId, skillId = skillId, from = from, to = to }); availibilityRepository.SaveChanges(); return(true); } else { ValidationSummary.Add(validation); return(false); } }
public void InvokeAttach_WhenPassedEntity() { var tweet = new Tweet { Id = "1284738912734897" }; var contextMock = new Mock <TwitterContext>(); var tweetsDbSetMock = new Mock <DbSet <Tweet> >(); contextMock.Setup(x => x.Set <Tweet>()) .Returns(tweetsDbSetMock.Object); tweetsDbSetMock.Setup(x => x.Attach(It.IsAny <Tweet>())) .Verifiable(); var tweetRepository = new GenericRepository <Tweet, string>(contextMock.Object); tweetRepository.Attach(tweet); tweetsDbSetMock.Verify(s => s.Attach(It.IsAny <Tweet>()), Times.Once); }
public bool UpdateHonor(string name, string description, string image) { var validation = string.Empty; if (this.IsHavingValidInputs(name, description, image)) { //Todo: Call the repository method to add and then to save honorRepository.Attach(new Model.Honor() { name = name, description = description, image = image }); honorRepository.SaveChanges(); return(true); } else { ValidationSummary.Add(validation); return(false); } }
public bool UpdateApplication(Guid userId, Guid taskId, Guid projectId, string euros) { var validation = string.Empty; if (this.IsHavingValidInputs(userId, taskId, euros)) { //Todo: Call the repository method to add and then to save applicationRepository.Attach(new Model.Application() { userId = userId, taskId = taskId, projectId = projectId, euro_Hr = euros }); applicationRepository.SaveChanges(); return(true); } else { ValidationSummary.Add(validation); return(false); } }
public bool UpdateFollowing(Guid organizationId, Guid projectId, Guid userId) { var validation = string.Empty; if (this.IsHavingValidInputs(organizationId, projectId, userId)) { //Todo: Call the repository method to add and then to save followingRepository.Attach(new Model.Following() { organizationId = organizationId, projectId = projectId, userId = userId }); followingRepository.SaveChanges(); return(true); } else { ValidationSummary.Add(validation); return(false); } }
public bool UpdateNewsFeed(Guid organizationId, Guid projectId, DateTime date, string feed, Guid followingId) { var validation = string.Empty; if (this.IsHavingValidInputs(organizationId, projectId, date, feed, followingId)) { //Todo: Call the repository method to add and then to save newsFeedRepository.Attach(new Model.NewsFeed() { organizationId = organizationId, projectId = projectId, date = date, followingId = followingId }); newsFeedRepository.SaveChanges(); return(true); } else { ValidationSummary.Add(validation); return(false); } }