Ejemplo n.º 1
0
        public string PostNewUser(User newUser)
        {
            try
            {
                using (RigaAppUserEntities entities = new RigaAppUserEntities())
                {
                    newUser.password = HashPass(newUser.password);
                    if (entities.Users.FirstOrDefault(e => e.username == newUser.username) == null)
                    {
                        if (entities.Users.FirstOrDefault(e => e.email == newUser.email) == null)
                        {
                            entities.Users.Add(newUser);
                            entities.SaveChanges();
                            message = "User " + newUser.username + " created successfully!";
                        }
                        else
                        {
                            message = "Email " + newUser.email + " already used!";
                        }
                    }
                    else
                    {
                        message = "Account with username " + newUser.username + " already exists.";
                    }


                    return(message);
                }
            }
            catch (Exception)
            {
                return("Something went wrong!");
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage PostNewUser(User newUser)
        {
            try
            {
                using (RigaAppUserEntities entities = new RigaAppUserEntities())
                {
                    newUser.password = HashPass(newUser.password);
                    entities.Users.Add(newUser);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, newUser);
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }