Esempio n. 1
0
        public IHttpActionResult PutTag(int id, Tag tag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tag.TagId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public IHttpActionResult PutBookmark(string id, Bookmark bookmark)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bookmark.UserId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 3
0
        public IHttpActionResult PutProduct(string id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            // This is how we update stuff
            var dbUsers = db.Users.Find(id);

            dbUsers.UserName        = user.UserName;
            dbUsers.ProfilePhotoUrl = user.ProfilePhotoUrl;
            dbUsers.Email           = user.Email;
            dbUsers.BirthDate       = user.BirthDate;
            dbUsers.ZipCode         = user.ZipCode;
            dbUsers.FirstName       = user.FirstName;
            dbUsers.LastName        = user.LastName;
            dbUsers.PhoneNumber     = user.PhoneNumber;


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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 4
0
        public IHttpActionResult PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.ProductId)
            {
                return(BadRequest());
            }

            // This is how we update stuff
            var dbProduct = db.Products.Find(id);

            dbProduct.Name          = product.Name;
            dbProduct.Description   = product.Description;
            dbProduct.Amount        = product.Amount;
            dbProduct.Condition     = product.Condition;
            dbProduct.CategoryId    = product.Category.CategoryId;
            dbProduct.ProductPhotos = product.ProductPhotos;

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }