Example #1
0
        public JsonResult Edit(string id, [Bind("DeveloperId,DeveloperName,DeveloperPhoneNumber,ShortDescription,CurrentCity,IsAvailableForJob")] ShortBio shortBio)
        {
            if (id != shortBio.DeveloperId)
            {
                return(null);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shortBio);
                    _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShortBioExists(shortBio.DeveloperId))
                    {
                        return(null);
                    }
                    else
                    {
                        throw;
                    }
                }
                return(Json(shortBio));
            }
            return(null);
        }
Example #2
0
        public async Task<IActionResult> Register(InitDevelopers initDevelopers, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var mailAddress = new MailAddress(initDevelopers.DevEmail);
                initDevelopers.DevId = Guid.NewGuid().ToString().Replace("-", "");
                
                var userObject = new IdentityUser
                {
                    Id = initDevelopers.DevId,
                    UserName = mailAddress.User,
                    Email = initDevelopers.DevEmail,
                    LockoutEnabled = false
                };
                var userCreationResult = await _userManager.CreateAsync(userObject, initDevelopers.DevPassword);

                if (userCreationResult.Succeeded)
                {
                    await _signInManager.SignInAsync(userObject, true);
                    
                    var shortBio = new ShortBio
                    {
                        DeveloperId = initDevelopers.DevId,
                        DeveloperName = mailAddress.User
                    };

                    var social = new SocialProfile
                    {
                        DeveloperId = initDevelopers.DevId
                    };

                    var workingProfile = new WorkingProfile
                    {
                        DeveloperId = initDevelopers.DevId
                    };

                    _context.Add(shortBio);
                    _context.Add(social);
                    _context.Add(workingProfile);
                    await _context.SaveChangesAsync();
                    
                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    return RedirectToAction("Edit", "ShortBios", new { id = initDevelopers.DevId });
                }
                
                foreach (var error in userCreationResult.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return View(initDevelopers);
        }