示例#1
0
        public async Task <IActionResult> PutUserProfileModel([FromRoute] int id, [FromBody] UserProfileModel userProfileModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userProfileModel.ID)
            {
                return(BadRequest());
            }

            _context.Entry(userProfileModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserProfileModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public IHttpActionResult PutUserProfile(int id, UserProfile userProfile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userProfile.Id)
            {
                return(BadRequest());
            }

            db.Entry(userProfile).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserProfileExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#3
0
        public ActionResult Edit(UserProfile userProfile)
        {
            byte[] salt     = PasswordEncryption.GenerateSalt();
            var    password = Encoding.UTF8.GetBytes(userProfile.Password);

            var hashedPassword = PasswordEncryption.HashPasswordWithSalt(password, salt);

            userProfile.Password = Convert.ToBase64String(hashedPassword);

            if (ModelState.IsValid)
            {
                db.Entry(userProfile).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(userProfile));
        }