Esempio n. 1
0
        public bool CreateUserInfo(UserInfoCreate model, HttpPostedFileBase file)
        {
            model.ProfileImage = ConvertToBytes(file);
            var ctx = new ApplicationDbContext();
            //var user = ctx.Users.Find(_userID);
            //_user = user;

            var entity =
                new UserInfo()
            {
                Id           = _userID,
                Name         = model.Name,
                Username     = model.Username,
                Bio          = model.Bio,
                Location     = model.Location,
                ProfileImage = model.ProfileImage,
                Interests    = model.Interests
            };

            using (ctx)
            {
                ctx.UsersInfo.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> CreateUser([FromBody] UserInfoCreate model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (!string.IsNullOrEmpty(model.RoleId))
                {
                    var role = await _roleManager.FindByIdAsync(model.RoleId);

                    await _userManager.AddToRoleAsync(user, role.Name);
                }

                if (result.Succeeded)
                {
                    return(await BuildToken(model));
                }
                else
                {
                    return(BadRequest("Username or Password invalid"));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Esempio n. 3
0
        public ActionResult Create(UserInfoCreate user)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase file = Request.Files["Image"];

                var service = CreateUserInfoService().CreateUserInfo(user, file);
                if (service)
                {
                    return(RedirectToAction("Details"));
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                //if (!service.Equals(1))
                //{
                //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                //}
            }
            return(View(user));
        }