Example #1
0
        public async Task <IHttpActionResult> GetUser([FromUri] int id, [FromUri] string password,
                                                      [FromUri] string userEmail)
        {
            Eventual.Model.User u = ValidateUser(userEmail, password);

            if (u == null)
            {
                return(Unauthorized());
            }

            Eventual.DAL.User user = await db.Users.FindAsync(id);

            if (user == null)
            {
                return(NotFound());
            }

            if (user.UserID != u.UserID)
            {
                return(Unauthorized());
            }

            db.Entry(user).State = System.Data.Entity.EntityState.Detached;
            return(Ok(user));
        }
        //converts User to User Model
        public static Eventual.Model.User UserEntityToUserModel(Eventual.DAL.User user)
        {
            Eventual.Model.User result = new Eventual.Model.User
            {
                UserBirthDate      = user.UserBirthDate,
                UserEmail          = user.UserEmail,
                UserEndDate        = user.UserEndDate,
                UserFirstName      = user.UserFirstName,
                UserStartDate      = user.UserStartDate,
                UserHashedPassword = user.UserHashedPassword,
                UserID             = user.UserID,
                UserImageURL       = user.UserImageURL,
                UserLastName       = user.UserLastName,
                UserPhoneNumber    = user.UserPhoneNumber,
                UserRole           = UserRoleEntityToUserRoleModel(user.UserRole),
                UserRoleID         = user.UserRoleID
            };

            return(result);
        }
Example #3
0
        public async Task <IHttpActionResult> GetUsersEvents([FromUri] int id, [FromUri] string userEmail,
                                                             [FromUri] string password)
        {
            Eventual.DAL.User user = await db.Users.FindAsync(id);

            Eventual.Model.User u = ValidateUser(userEmail, password);

            if (u == null)
            {
                return(Unauthorized());
            }

            //return a bad request response
            if (user == null)
            {
                return(BadRequest(ModelState));
            }

            //returns an ok with status code
            return(Ok(GetAllUsersEvents(id)));
        }
Example #4
0
        public async Task <IHttpActionResult> DeleteUser([FromUri] int id)
        {
            Eventual.DAL.User user = await db.Users.FindAsync(id);

            if (user == null)
            {
                return(NotFound());
            }

            DropRegisteredEvents(id);

            await db.SaveChangesAsync();

            DropSavedEvents(id);
            await db.SaveChangesAsync();

            db.Users.Remove(user);

            await db.SaveChangesAsync();

            return(Ok(user));
        }
Example #5
0
        public async Task <IHttpActionResult> SignUpUser([FromBody] Eventual.Model.User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (db.Users.Count(u => u.UserEmail == user.UserEmail) > 0)
            {
                return(BadRequest("Please login."));
            }

            user.UserHashedPassword = ComputeHash(user.UserHashedPassword, new SHA256CryptoServiceProvider(),
                                                  Encoding.ASCII.GetBytes(GetDBSALT()));
            Eventual.DAL.User DALUser = ConvertModels.ConvertModelToEntity.UserModelToUserEntity(user);
            db.spCreateUser(DALUser.UserEmail, DALUser.UserHashedPassword);
            await db.SaveChangesAsync();

            Eventual.Model.User newUser =
                ConvertModels.ConvertEntityToModel.UserEntityToUserModel(db.Users.FirstOrDefault(u => u.UserEmail == user.UserEmail));
            return(Ok(newUser));
        }
        //converts User to User Model
        public static Eventual.DAL.User UserModelToUserEntity(Eventual.Model.User user)
        {
            Eventual.DAL.User result = new Eventual.DAL.User
            {
                UserID             = user.UserID,
                UserBirthDate      = user.UserBirthDate,
                UserStartDate      = user.UserStartDate,
                UserEmail          = user.UserEmail,
                UserEndDate        = user.UserEndDate,
                UserFirstName      = user.UserFirstName,
                UserLastName       = user.UserLastName,
                UserHashedPassword = user.UserHashedPassword,
                UserImageURL       = user.UserImageURL,
                UserPhoneNumber    = user.UserPhoneNumber,
                UserRoleID         = user.UserRoleID,
                UserRole           = UserRoleModelToUserRoleEntity(user.UserRole),
                EventRegistrations = EventRegistrationsModelToEventRegistrationsEntity(user.EventRegistrations),
                SavedEvents        = SavedEventsModelToSavedEventsEntity(user.SavedEvents)
            };

            return(result);
        }