Ejemplo n.º 1
0
        public CoreModels.User ChangeUser(CoreModels.UserWithLoginAndAvatar userWithLoginAndAvatar, string image)
        {
            var user = _dbContext.Users
                       .Include(u => u.Passcode)
                       .Include(u => u.UserPhoto)
                       .First(u => u.Id.ToString() == userWithLoginAndAvatar.User.Id);

            user.Name  = userWithLoginAndAvatar.User.Username;
            user.Email = userWithLoginAndAvatar.User.Email;

            if (user.UserPhoto == null)
            {
                var userPhoto = new DbModels.UserPhoto(user.Id, image);
                _dbContext.UserPhotos.Add(userPhoto);
            }
            else
            {
                var userPhoto = _dbContext.UserPhotos
                                .First(up => up.Id == user.Id);
                userPhoto.Image = image;
                _dbContext.Entry(userPhoto).State = EntityState.Modified;
            }

            var passcode = _dbContext.Passcodes
                           .First(p => p.Id == user.Id);

            _dbContext.Entry(user).State     = EntityState.Modified;
            _dbContext.Entry(passcode).State = EntityState.Modified;
            _dbContext.SaveChanges();

            return(new CoreModels.User(user.Id.ToString(),
                                       user.Name,
                                       user.Email,
                                       image));
        }
Ejemplo n.º 2
0
        public CoreModels.NoteAllContent ChangeNoteText(Guid userId, Guid noteId, CoreModels.INoteContent[] noteContent)
        {
            string dbContent = "";

            foreach (var content in noteContent)
            {
                if (content.Type == "text")
                {
                    var textContent = (CoreModels.NoteTextContent)content;
                    dbContent += textContent.Text;
                    Console.WriteLine(textContent.Text);
                }
                else if (content.Type == "file")
                {
                    var fileContent = (CoreModels.NoteFileContent)content;
                    dbContent += $"![{fileContent.FileId}]({fileContent.FileName})\n";
                }
            }

            var userNote = _dbContext.UserNotes
                           .Include(un => un.Note)
                           .ThenInclude(n => n.TextNote)
                           .Include(un => un.User)
                           .ThenInclude(u => u.Passcode)
                           .Include(un => un.User)
                           .ThenInclude(u => u.UserPhoto)
                           .First(un => un.UserId == userId && un.NoteId == noteId);

            userNote.Note.TextNote.Text      = dbContent;
            _dbContext.Entry(userNote).State = EntityState.Modified;
            _dbContext.SaveChanges();

            return(new CoreModels.NoteAllContent(new CoreModels.Note(noteId.ToString(),
                                                                     userNote.Note.Header,
                                                                     userRightsToStr(userNote.Rights)),
                                                 noteContent));
        }
Ejemplo n.º 3
0
        public CoreModels.NoteAccessRight ChangeUserNote(Guid changeUserId, Guid userId, Guid noteId,
                                                         string userRights)
        {
            var userNote = _dbContext.UserNotes
                           .Include(un => un.Note)
                           .ThenInclude(n => n.TextNote)
                           .Include(un => un.User)
                           .ThenInclude(u => u.Passcode)
                           .Include(un => un.User)
                           .ThenInclude(u => u.UserPhoto)
                           .First(un => un.UserId == userId && un.NoteId == noteId);

            userNote.Rights = (DbModels.Enums.UserRights)Enum.Parse(typeof(DbModels.Enums.UserRights), userRights.ToString());
            _dbContext.Entry(userNote).State = EntityState.Modified;
            _dbContext.SaveChanges();

            return(new CoreModels.NoteAccessRight(userNote.NoteId.ToString(),
                                                  userNote.UserId.ToString(),
                                                  userRights));
        }