Ejemplo 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));
        }
Ejemplo 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));
        }
Ejemplo n.º 3
0
        private void SeedProducts(ListItDataContext context)
        {
            foreach (var user in context.Users)
            {
                int randomNumber = Faker.NumberFaker.Number(0, 5);

                for (int i = 0; i < randomNumber; i++)
                {
                    var product = new Product
                    {
                        UserId      = user.Id,
                        Active      = Faker.BooleanFaker.Boolean(),
                        Amount      = Faker.NumberFaker.Number(10, 2000).ToString(),
                        CategoryId  = Faker.NumberFaker.Number(1, context.Categories.Count()),
                        Condition   = Faker.NumberFaker.Number(1, 6),
                        Description = Faker.TextFaker.Sentences(2),
                        Name        = Faker.TextFaker.Sentence(),
                        Posted      = Faker.DateTimeFaker.DateTime(DateTime.Now.AddYears(-1), DateTime.Now)
                    };

                    context.Products.Add(product);
                }
            }

            context.SaveChanges();
        }
Ejemplo 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));
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        private void SeedCategories(ListItDataContext context)
        {
            context.Categories.AddOrUpdate(
                c => c.Name,
                new Category {
                Name = "Antique"
            },
                new Category {
                Name = "Appliances"
            },
                new Category {
                Name = "Bikes"
            },
                new Category {
                Name = "Boats"
            },
                new Category {
                Name = "Cars"
            },
                new Category {
                Name = "Books"
            },
                new Category {
                Name = "Phones"
            },
                new Category {
                Name = "Trailers"
            },
                new Category {
                Name = "Video Games"
            },
                new Category {
                Name = "Electronics"
            },
                new Category {
                Name = "Wanted"
            },
                new Category {
                Name = "Other"
            }
                );

            context.SaveChanges();
        }