public UserStorageVM GetUserStorages(UserProfileInfo userProfile) { UserStorageVM model = new UserStorageVM(); List<AuthCredential> credentials = this.repoAuthCredential .GetByUserId(userProfile.Id) .Where(c => c.Status != CredentialStatus.Canceled) .ToList(); var values = from MoG.Domain.Models.CloudStorageServices e in Enum.GetValues(typeof(MoG.Domain.Models.CloudStorageServices)) select new { Id = e, Name = e.ToString() }; foreach (var cloudStorage in Enum.GetValues(typeof(MoG.Domain.Models.CloudStorageServices))) { CloudStorageServices currentCloudStorage = (CloudStorageServices)cloudStorage; var userCredentials = credentials.Where(c => c.CloudService == currentCloudStorage).ToList(); if (userCredentials.Count > 0) { model.CloudStorages.AddRange(userCredentials); } else { model.CloudStorages.Add(new AuthCredential() { CloudService = currentCloudStorage, Status = CredentialStatus.NotRegistered }); } } return model; }
public string AskForRegistrationUrl(UserProfileInfo user, string redirectUrl, out int tempCredentialId) { var _client = new DropNetClient(MogConstants.DROPBOX_KEY, MogConstants.DROPBOX_SECRET); UserLogin login = _client.GetToken(); // UserLogin login = _client.GetAccessToken(); var url = _client.BuildAuthorizeUrl(login, redirectUrl); var query = repoAuthCredential.GetByUserId(user.Id); List<AuthCredential> existingCredentials = null; if (query != null) {//TODO : gerer le cas des accounts multiples existingCredentials = query.Where(a => a.CloudService == CloudStorageServices.Dropbox).ToList(); foreach (var credential in existingCredentials) { repoAuthCredential.Delete(credential); } } AuthCredential newCredential = new AuthCredential(); newCredential.Token = login.Token; newCredential.Secret = login.Secret; newCredential.UserId = user.Id; newCredential.CloudService = CloudStorageServices.Dropbox; this.repoAuthCredential.Create(newCredential); tempCredentialId = newCredential.Id; return url; }
public bool Create(UserProfileInfo usr) { if (usr.LastNotificationDate == DateTime.MinValue) usr.LastNotificationDate = DateTime.Now; dbContext.Users.Add(usr); int result = dbContext.SaveChanges(); return (result > 0); }
public string AskForRegistrationUrl(UserProfileInfo user, string redirectUrl, out int tempCredentialId) { LiveAuthClient auth = new LiveAuthClient(clientId, clientSecret, redirectUrl); string url = auth.GetLoginUrl(scopes); tempCredentialId = -1; return url; }
public Message Archive(int id, UserProfileInfo currentUser) { //var message = GetById(id); Message result = null; result = repositoryMessage.Archive(id, currentUser.Id); return result; }
private bool isEditFileGranted(object context, UserProfileInfo user) { ProjectFile f = context as ProjectFile; if (f==null || f.Creator == null || user == null) { return false; } return f.Creator.Id == user.Id; }
public void Social_GetFriends() { UserProfileInfo user = new UserProfileInfo(); user.Id = 1; var friends = this.service.GetFriends(user); Assert.IsNotNull(friends); Assert.IsTrue(friends.Count > 0); }
public int AddToCart(int fileId, UserProfileInfo user) { DownloadCartItem item = new DownloadCartItem(); item.FileId = fileId; item.User = user; item = this.dbContext.DownloadCarts.Add(item); this.dbContext.SaveChanges(); return item.Id; }
public bool Delete(int id, UserProfileInfo user) { if (id <= 0) return false; DownloadCartItem item = this.repoDownloadCart.GetById(id); if (item.User.Id != user.Id) { return false; } return this.repoDownloadCart.Delete(item); }
public bool Register(UserProfileInfo user,string code) { RegistrationCode reg = this.GetByCode(code); if (reg.User != null) { return false; } reg.RegistratedOn = DateTime.Now; reg.User = user; this.repoRegCode.SaveChanges(reg); return true; }
public bool HasRight(SecureActivity activity, UserProfileInfo user, object context) { if (user == null) { return false; } if (this.hasRightMethods.ContainsKey(activity)) { return this.hasRightMethods[activity](user, context); } else return false; }
public bool Delete(int id,UserProfileInfo userProfile) { Comment commentToDelete = GetById(id); if (commentToDelete.Creator.Id != userProfile.Id) { return false; } var flag = this.servActivity.DeleteByCommentId(id); if (!flag) return false; this.servActivity.DeleteByCommentId(id); return this.repoComment.DeleteById(id); }
public int AddToCart(int fileId, UserProfileInfo user) { if (fileId <= 0) return -1; if (user == null || user.Id < 0) { return -1; } var preExisitingItem = this.repoDownloadCart.GetByUserId(user.Id).Where(d => d.FileId == fileId).FirstOrDefault(); if (preExisitingItem != null) return preExisitingItem.Id; this.serviceFile.IncrementDownloadCount(fileId); return this.repoDownloadCart.AddToCart(fileId, user); }
public void CreateOrSave(UserProfileInfo infos) { var test = this.dbContext.Users .Where(u => u.AppUserId == infos.AppUserId) .FirstOrDefault(); if (test == null) { this.Create(infos); } else { this.SaveChanges(infos); } }
public void SecurityService_EditProject() { //arrange UserProfileInfo u1 = new UserProfileInfo() { Login = "******" }; UserProfileInfo u2 = new UserProfileInfo() { Login = "******" }; Project p1 = new Project() { Creator = u1 }; //act bool test1 = this.serviceSecurity.HasRight(SecureActivity.ProjectEdit, u2, p1); bool test2 = this.serviceSecurity.HasRight(SecureActivity.ProjectEdit, u1, p1); //assert Assert.IsFalse(test1,"u2 is not the creator -> does not has the right to edit"); Assert.IsTrue(test2,"u1 is the creator -> has the right to edit"); }
public bool IsOwner(Project project, UserProfileInfo user) { return project.Creator.Login == user.Login; }
public bool Delete(int id, UserProfileInfo deletor) { bool result = false; Project p = GetById(id); if (p != null) { p.DeletedOn = DateTime.Now; p.DeletedBy = deletor; p.Deleted = true; this.projectRepo.SaveChanges(p); result = true; } return result; }
public int SaveChanges(UserProfileInfo user) { if (user.LastNotificationDate == DateTime.MinValue) user.LastNotificationDate = DateTime.Now; this.dbContext.Entry(user).State = EntityState.Modified; this.dbContext.SaveChanges(); return user.Id; }
private SendNotificationVM sendNotification(UserProfileInfo user, List<Notification> notifs) { SendNotificationVM result = new SendNotificationVM(); result.User = user; result.Notifications = notifs.Where(n => n.UserId == user.Id).ToList(); return result; }
public IList<UserProfileInfo> GetFriends(UserProfileInfo user) { return this.repoUser.GetFriends(user.Id); }
public bool Cancel(int projectId, UserProfileInfo User) { bool result = true; var files = GetByProjectId(projectId, User); foreach (var file in files) { result &= this.DeleteById(file.Id); } return result; }
public IList<TempUploadedFile> GetByProjectId(int id, UserProfileInfo user) { return this.fileRepo.GetByProjectId(id, user.Id).ToList(); }
public bool IsFollowed(Project project, UserProfileInfo user) { if (project == null || user == null) return false; return this.repo.IsFollowed(project.Id, user.Id); }
public int Create(Project project, UserProfileInfo userProfile) { project.CreatedOn = DateTime.Now; project.ModifiedOn = DateTime.Now; project.Creator = userProfile; project.Likes = 0; project.ImageUrl = "~/Content/Images/nothingyetbw.png";//http://placehold.it/700*400 project.ImageUrlThumb1 = "~/Content/Images/nothingyetbw.png";// "http://placehold.it/350x200"; if (projectRepo.Create(project)) { serviceActivity.LogProjectCreation(project); return project.Id; } return -1; }
public Message Send(Message newMessage, UserProfileInfo from, IEnumerable<int> destinationIds, int? replyTo = null) { bool result = true; IEnumerable<UserProfileInfo> destinations = serviceUser.GetByIds(destinationIds); newMessage.CreatedBy = from; newMessage.CreatedOn = DateTime.Now; newMessage.SentTo = destinations.Select(u => u.DisplayName).Aggregate((current, next) => current + ", " + next); result &= repositoryMessage.Create(newMessage); result &= repositoryMessage.Send(newMessage, destinations,replyTo); return newMessage; }
public bool IsPermissionGranted(MoGPermission perm, Object context,UserProfileInfo user) { return permissionEvaluator[perm](context, user); }
public bool IsInvited(Project project, UserProfileInfo user) { return this.repoInvit.IsInvited(project.Id, user.Id); }
/// <summary> /// store the byte[] locally and create a record in the tempfile table /// </summary> /// <param name="file"></param> /// <param name="userProfile"></param> /// <returns></returns> public int Create(TempUploadedFile file, UserProfileInfo userProfile) { file.Creator = userProfile; file.Status = Models.ProcessStatus.UploadInProgress; file.FailedCount = 0; try { file.Path = Guid.NewGuid().ToString() + file.Name; this.serviceLocalStorage.UploadFile(file.Data, file.Path, _container); } catch (Exception exc) { this.serviceLog.LogError("TempFileService::Create", exc); return -1; } if (this.fileRepo.Create(file)) { return file.Id; } return -1; }
public int Invit(int projectId, int userId, string message, UserProfileInfo currentUser) { Invit test = this.repoInvit.Get(projectId, userId); if (test != null) { test.Message = message; test.ModifiedOn = DateTime.Now; test.Status = InvitStatus.Pending; this.repoInvit.SaveChanges(test); return test.Id; } Invit Invit = new Invit() { ProjectId = projectId , UserId = userId , CreatedBy = currentUser ,Status = InvitStatus.Pending ,Message = message }; int createdId = this.repoInvit.Create(Invit); return createdId; }
private VMProfile mapdata(UserProfileInfo user) { //todo use automapper VMProfile model = null; if (user != null) { var stats = serviceStatistics.GetStatByUserId(user.Id); model = new VMProfile(); model.Id = user.Id; model.Stats = stats; model.DisplayName = user.DisplayName; model.Email = user.Email; model.Login = user.Login; model.PictureUrl = user.PictureUrl; model.CreatedOn = user.CreatedOn; } return model; }