Exemplo n.º 1
0
        public Flower Create(FlowerPostModel flower, User addedBy)
        {
            // TODO: how to store the user that added the flower as a field in Flower?
            Flower toAdd = FlowerPostModel.ToFlower(flower);

            toAdd.Owner = addedBy;
            context.Flowers.Add(toAdd);
            context.SaveChanges();
            return(toAdd);
        }
Exemplo n.º 2
0
        public UserGetModel Register(RegisterPostModel registerInfo)
        {
            User existing = context.Users.FirstOrDefault(u => u.Username == registerInfo.Username);

            if (existing != null)
            {
                return(null);
            }

            context.Users.Add(new User
            {
                Email     = registerInfo.Email,
                LastName  = registerInfo.LastName,
                FirstName = registerInfo.FirstName,
                Password  = ComputeSha256Hash(registerInfo.Password),
                Username  = registerInfo.Username,
                UserRole  = UserRole.Regular
            });
            context.SaveChanges();
            return(Authenticate(registerInfo.Username, registerInfo.Password));
        }