Exemplo n.º 1
0
        public IHttpActionResult PostUser(Users_tbl user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Users_tbl.Add(user);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (UserExists(user.Password))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = user.Password }, user));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            Movie_ReviewDBEntities db = new Movie_ReviewDBEntities();
            Users_tbl auser           = new Users_tbl();

            auser.UserName = model.UserName;
            auser.Country  = model.Country;
            //db.Users_tbl.Add(auser);
            //db.SaveChanges();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email, PhoneNumber = model.Country
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 3
0
        public IHttpActionResult GetUser(string id)
        {
            Users_tbl user = db.Users_tbl.Find(id);

            if (user == null)
            {
                return(NotFound());
            }

            return(Ok(user));
        }
Exemplo n.º 4
0
        public IHttpActionResult DeleteUser(string id)
        {
            Users_tbl user = db.Users_tbl.Find(id);

            if (user == null)
            {
                return(NotFound());
            }

            db.Users_tbl.Remove(user);
            db.SaveChanges();

            return(Ok(user));
        }