Esempio n. 1
0
        public UserInfo RegisterUser(RegistrationInfo registerationInfo)
        {
            var username = registerationInfo.UserName.ToUpper();
            var email    = registerationInfo.Email.ToUpper();
            var duplUser = dbContext.Users.SingleOrDefault(u => u.Username.ToUpper() == username || u.Email.ToUpper() == email);

            if (duplUser != null)
            {
                throw new DuplicateUserException();
            }
            var user = new User
            {
                Username = registerationInfo.UserName,
                Email    = registerationInfo.Email,
                Password = crypto.Hash(registerationInfo.Password)
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();
            return(new UserInfo
            {
                Username = user.Username,
                Email = user.Email
            });
        }
Esempio n. 2
0
 private void CreateTestUser()
 {
     landmarkRemarkContext.Users.Add(new User {
         Username = "******", Email = "*****@*****.**", Password = "******"
     });
     landmarkRemarkContext.Users.Add(new User {
         Username = "******", Email = "*****@*****.**", Password = "******"
     });
     landmarkRemarkContext.SaveChanges();
 }
Esempio n. 3
0
        // helpful for seeding in unit test class construct
        public User Add(User user)
        {
            var result = _context.Users.Add(user);

            // to trigger validation
            _context.SaveChanges();

            return(result.Entity);
        }
        public Note Add(Note note)
        {
            var result = _context.Notes.Add(note);

            // to trigger validation
            _context.SaveChanges();

            return(result.Entity);
        }
Esempio n. 5
0
        public int CreateNote(string username, Geometry location, string text)
        {
            var user = dbContext.Users.FirstOrDefault(u => u.Username == username);

            if (user == null)
            {
                throw new UserNotFoundException($"{username} not found.");
            }
            var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);
            var point           = location as  GeometryPoint;
            var geoPoint        = geometryFactory.CreatePoint(new NetTopologySuite.Geometries.Coordinate(point.X, point.Y));

            var note = new Data.DataModels.Note
            {
                Body     = text,
                Owner    = user,
                Location = geoPoint
            };

            dbContext.Notes.Add(note);
            dbContext.SaveChanges();
            return(note.Id);
        }
        private void CreateDataForTests(LandmarkRemarkContext context)
        {
            var users = new[]
            {
                new User
                {
                    FirstName = "Steve", LastName = "Smith", UserName = "******", UserNotes = new List <Note>
                    {
                        new Note {
                            Text = "Great place to visit", Location = new Point(145.1257112, -37.9131133), AddedOn = DateTimeProvider.Now()
                        }
                    }
                },
                new User
                {
                    FirstName = "Tom", LastName = "Cruise", UserName = "******", UserNotes = new List <Note>
                    {
                        new Note
                        {
                            Text = "Great place to visit", Location = new Point(153.0272569, -27.4640302), AddedOn = DateTimeProvider.Now()
                        },
                        new Note {
                            Text = "Great food", Location = new Point(152.9986068, -27.4522202), AddedOn = DateTimeProvider.Now()
                        }
                    }
                },

                new User {
                    FirstName = "Peter", LastName = "Mccormack", UserName = "******"
                }
            };

            foreach (var user in users)
            {
                (byte[] passwordHash, byte[] passwordSalt) = CreatePasswordHash($"{user.FirstName}{user.LastName}");
                user.PasswordHash = passwordHash;
                user.PasswordSalt = passwordSalt;
            }

            context.Users.AddRange(users);
            context.SaveChanges();
        }
        public async Task <int> Handle(CreateNoteCommand request, CancellationToken cancellationToken)
        {
            var user = await _context.Users.SingleOrDefaultAsync(m => m.Id == request.UserId);

            //We could have decided to not take int as parameter in validator in this case, but it gives us better flexibility
            //we could also query database for userid existence, but to avoid  double trip, we check with user instead
            var validator = new CreateNoteCommandValidator((x) => user != null);

            validator.ValidateAndThrowUnProcessableEntityException(request);

            var note = new Note
            {
                Text     = request.Text,
                Location = new Point(request.Longitude, request.Latitude),
                AddedOn  = _timeProvider.Now()
            };

            user.UserNotes.Add(note);

            _context.SaveChanges();
            return(note.Id);
        }