public UserMoneyModel GetUser(string sessionKey) { var context = new BankSystemEntities(); using (context) { var user = context.Users.FirstOrDefault( u => u.AuthKey == sessionKey); if (user == null) { throw new InvalidOperationException("No user with such sessionKey logged"); } else { var model = new UserMoneyModel() { Id = user.Id, AvelableMoney = user.AvelableMoney }; return model; } } }
public HttpResponseMessage PutLogoutUser(int money,string sessionKey) { var context = new BankSystemEntities(); using (context) { var user = context.Users.FirstOrDefault(u => u.AuthKey == sessionKey); if (user==null) { throw new InvalidOperationException("There is no such user loged"); } user.AvelableMoney = money; context.SaveChanges(); var model = new UserMoneyModel() { Id = user.Id, AvelableMoney = user.AvelableMoney }; var response = this.Request.CreateResponse(HttpStatusCode.OK,model); return response; } }