Example #1
0
        //Add User to DB
        public string AddUser(userDTO user)
        {
            string message = "";

            var checkedUser = from u in DB.Users
                              where user.nameOfUser == u.userName
                              select user.nameOfUser;

            if (!checkedUser.Any())
            {
                User userToAdd = new User
                {
                    userFirstName = user.firstName,
                    userLastName  = user.lastName,
                    userID        = user.IdOfUser,
                    userName      = user.nameOfUser,
                    userBirthDate = user.dateOfBirth,
                    userEmail     = user.email,
                    userGender    = user.gender,
                    userPasword   = user.password,
                    userImage     = user.image,
                    userRole      = user.role
                };
                DB.Users.Add(userToAdd);
                DB.SaveChanges();
                message = "User successfuly created";
                return(message);
            }
            else
            {
                message = "User with name " + user.nameOfUser + " is already exist! please choose another name";
                return(message);
            }
        }
Example #2
0
 public HttpResponseMessage GetUser(logInDTO logIn)
 {
     try
     {
         userDTO userFound = logic.GetUser(logIn);
         return(Request.CreateResponse(HttpStatusCode.OK, userFound));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(
                    HttpStatusCode.InternalServerError,
                    ErrorsManager.GetInnerMessage(ex)));
     }
 }
Example #3
0
        public HttpResponseMessage AddProduct(userDTO user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  ErrorsManager.GetErrors(ModelState)));
                }

                string addedProduct = logic.AddUser(user);
                return(Request.CreateResponse(HttpStatusCode.Created, addedProduct));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.InternalServerError,
                           ErrorsManager.GetInnerMessage(ex)));
            }
        }