Пример #1
0
 public ActionResult Unfollow([FromQuery] string username = null)
 {
     using (var context = new InstacramDbContext()) {
         if (username == null)
         {
             return(BadRequest("Malformed Request"));
         }
         var user = context.GetUserByUsername(username);
         if (user == null)
         {
             return(Ok());
         }
         context.RemoveFollow(Int32.Parse(this.User.Identity.Name), user.Id);
         return(Ok("Success"));
     }
 }
Пример #2
0
        public Object Register(string username, string password, string email, string name)
        {
            using (var context = new InstacramDbContext()) {
                var user = context.GetUserByUsername(username);
                // return null if user not found
                if (user != null)
                {
                    return(null);
                }

                // register new user
                // user = new User (username, password, email, name);
                // context.Users.Add (user);
                // context.SaveChanges ();
                user = context.AddUser(username, password, email, name);
                string strToken = GenerateToken(user);
                return(new { token = strToken });
            }
        }
Пример #3
0
 public ActionResult Get([FromQuery] int id = -1, string username = null)
 {
     using (var context = new InstacramDbContext()) {
         if (id == -1 && username == null)
         {
             return(Ok(context.GetFormattedUser(Int32.Parse(this.User.Identity.Name))));
         }
         if (id != -1 && username != null)
         {
             return(BadRequest("Malformed Request"));
         }
         var user = context.GetUserById(id) ?? context.GetUserByUsername(username);
         if (user == null)
         {
             return(NotFound("User Not Found"));
         }
         return(Ok(context.GetFormattedUser(user.Id)));
     }
 }