Example #1
0
        public CoreModels.User CreateUser(CoreModels.UserWithLogin userWithLogin)
        {
            var user = new DbModels.User(userWithLogin.User.Username,
                                         userWithLogin.User.Email,
                                         DateTime.Now);

            var passcode = new DbModels.Passcode(user.Id, userWithLogin.Login.Password);

            _dbContext.Users.Add(user);
            _dbContext.Passcodes.Add(passcode);
            _dbContext.SaveChanges();

            return(new CoreModels.User(user.Id.ToString(),
                                       user.Name,
                                       user.Email,
                                       null));
        }
Example #2
0
        public CoreModels.NoteAccessRight CreateUserNote(Guid changeUserId, Guid userId, Guid noteId,
                                                         string userRights)
        {
            var user = _dbContext.Users
                       .Include(un => un.Passcode)
                       .Include(un => un.UserPhoto)
                       .First(u => u.Id == userId);
            var note = _dbContext.Notes
                       .Include((un => un.TextNote))
                       .First(n => n.Id == noteId);

            var userNote = new DbModels.UserNote(convertStrToUseRights(userRights), userId, user, noteId, note);

            _dbContext.UserNotes.Add(userNote);
            _dbContext.SaveChanges();

            return(new CoreModels.NoteAccessRight(userNote.NoteId.ToString(),
                                                  userNote.UserId.ToString(),
                                                  userRights));
        }
Example #3
0
        public CoreModels.Note CreateNote(Guid userId, string name)
        {
            var note     = new DbModels.Note(name, DateTime.Now, DateTime.Now);
            var textNote = new DbModels.TextNote(note.Id, "");
            var user     = _dbContext.Users
                           .Include(u => u.Passcode)
                           .Include(u => u.UserPhoto)
                           .First(u => u.Id == userId);
            var userNote = new DbModels.UserNote(DbModels.Enums.UserRights.author,
                                                 userId, user,
                                                 note.Id,
                                                 note);

            _dbContext.Notes.Add(note);
            _dbContext.TextNotes.Add(textNote);
            _dbContext.UserNotes.Add(userNote);
            _dbContext.SaveChanges();

            return(new CoreModels.Note(note.Id.ToString(),
                                       note.Header,
                                       "author"));
        }