Exemplo n.º 1
0
        public async Task <IHttpActionResult> PutUserSiteLink(long id, UserSiteLink userSiteLink)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> AddUpdateUserBio(UserBio userBio)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            bool isEdit = false;

            //userBio.Id = this.LoggedInUserId;

            if (this.LoggedInUserId != userBio.Id)
            {
                return(BadRequest());
            }

            if (this.LoggedInAspNetUser.UserBio == null)
            {
                //ModelState.AddModelError("UserBioNotFound", "No record found to be updated");
                //return BadRequest(ModelState);
                isEdit = false;
                db.UserBios.Add(userBio);
            }

            if (this.LoggedInAspNetUser.UserBio != null)
            {
                isEdit = true;
                db.Entry(userBio).State = EntityState.Modified;
            }

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                Logger.Error(ex);
                throw;
            }
            catch (DbUpdateException dbex)
            {
                Logger.Error(dbex);

                if (UserBioExists(userBio.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            if (!isEdit)
            {
                return(CreatedAtRoute("DefaultApi", new { id = userBio.Id }, userBio));
            }

            db.Dispose();

            HttpResponseMessage Updateresponse = new HttpResponseMessage(HttpStatusCode.OK);

            Updateresponse.Content = new StringContent("Record Updated Successfully");
            return(Ok("Record Updated Successfully"));
        }