Exemple #1
0
        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;
        }
Exemple #2
0
        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;
        }
Exemple #3
0
 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);
 }
Exemple #4
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;
        }
Exemple #5
0
        public Message Archive(int id, UserProfileInfo currentUser)
        {
            //var message = GetById(id);
            Message result = null;

            result = repositoryMessage.Archive(id, currentUser.Id);

            return result;
        }
Exemple #6
0
 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;
 }
Exemple #7
0
        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;
 }
Exemple #9
0
 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;
 }
Exemple #11
0
 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;
 }
Exemple #12
0
 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);
 }
Exemple #13
0
 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);
 }
Exemple #14
0
 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);
     }
 }
Exemple #15
0
        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");
        }
Exemple #16
0
 public bool IsOwner(Project project, UserProfileInfo user)
 {
     return project.Creator.Login == user.Login;
 }
Exemple #17
0
 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;
 }
Exemple #18
0
 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;
 }
Exemple #19
0
 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;
 }
Exemple #20
0
 public IList<UserProfileInfo> GetFriends(UserProfileInfo user)
 {
     return this.repoUser.GetFriends(user.Id);
 }
Exemple #21
0
 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;
 }
Exemple #22
0
 public IList<TempUploadedFile> GetByProjectId(int id, UserProfileInfo user)
 {
     return this.fileRepo.GetByProjectId(id, user.Id).ToList();
 }
Exemple #23
0
 public bool IsFollowed(Project project, UserProfileInfo user)
 {
     if (project == null || user == null)
         return false;
     return this.repo.IsFollowed(project.Id, user.Id);
 }
Exemple #24
0
        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;
        }
Exemple #25
0
        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;
        }
Exemple #26
0
 public bool IsPermissionGranted(MoGPermission perm, Object context,UserProfileInfo user)
 {
     return permissionEvaluator[perm](context, user);
 }
Exemple #27
0
 public bool IsInvited(Project project, UserProfileInfo user)
 {
     return this.repoInvit.IsInvited(project.Id, user.Id);
 }
Exemple #28
0
 /// <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;
 }
Exemple #29
0
        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;
        }
Exemple #30
0
        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;
        }