Beispiel #1
0
 public string Authorize(string nickname, string password)
 {
     User user = _db.User.FirstOrDefault(u => ((u.Nickname == nickname) && (u.Password == password)));
     JsonResult jsonResult;
     if (user == null)
     {
         jsonResult = new JsonResult("invalid nickname/password");
         return JsonConvert.SerializeObject(jsonResult);
     }
     jsonResult = new JsonResult(new List<Dictionary<string, object>>
     {
         new Dictionary<string, object>
         {
             {"userId", user.ID},
             {"firstName", user.FirstName},
             {"lastName", user.LastName},
             {"info", user.Info}
         }
     });
     return JsonConvert.SerializeObject(jsonResult);
 }
Beispiel #2
0
 public string Register(string nickname, string password, string firstName, string lastName, string info)
 {
     if (_db.User.Any() && _db.User.Any(u => u.Nickname == nickname))
         return JsonConvert.SerializeObject(new JsonResult("another user have the same nickname"));
     User user = new User
     {
         Nickname = nickname,
         Password = password,
         FirstName = firstName,
         LastName = lastName,
         Info = info,
         ID = Guid.NewGuid()
     };
     JsonResult jsonResult;
     try
     {
         _db.User.Add(user);
         _db.SaveChanges();
     }
     catch (Exception)
     {
         jsonResult = new JsonResult("unknown error occured while adding a new record in data base");
         return JsonConvert.SerializeObject(jsonResult);
     }
     jsonResult = new JsonResult(new List<Dictionary<string, object>>());
     return JsonConvert.SerializeObject(jsonResult);
 }