コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        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;
            }
        }