예제 #1
0
        public User AddUser(NewUserStateModal newUser)
        {
            using(var ctx = new AlfasoftDBContext()){
                if(!ctx.Users.Any(u => u.Name.Equals(newUser.Name) || u.Number == newUser.Id)){
                    var user = newUser.getModel();

                    ctx.Users.Add(user);
                    ctx.SaveChanges();
                    return user;
                }
            }
            return null;
        }
        public HttpResponseMessage AddUser(NewUserStateModal newUser)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            var store = UserStore.getInstance();
            var user = store.AddUser(newUser);

            if (user!=null)
                return Request.CreateResponse(new UserStateModal(user));
            return Request.CreateResponse(HttpStatusCode.BadRequest);
        }