Exemplo n.º 1
0
        public void Delete(int id)
        {
            var item = _context.Categorys.First(x => x.CategoryID == id);

            _context.Categorys.Remove(item);
            _context.SaveChanges();
        }
        public ActionResult PostCategory([FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data"));
            }

            var cats = from q in context.Categories
                       select q;

            cats = cats.Where(q => q.Name.Equals(category.Name));

            if (cats != null && cats.Any())
            {
                return(BadRequest("Duplicate category name"));
            }

            context.Categories.Add(category);
            context.SaveChanges();

            return(CreatedAtRoute(
                       routeName: "GetCategory",
                       routeValues: new { id = category.Id },
                       value: category));
        }
        public Categories Create(CreateCategoryRequest request)
        {
            var added = request.Adapt <Categories>();

            _context.Categories.Add(added);
            _context.SaveChanges();
            return(added);
        }
Exemplo n.º 4
0
 public ActionResult Create(Categoria category) // POST
 {
     if (ModelState.IsValid)
     {
         _context.Categorys.Add(category);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("Create", category));
 }
Exemplo n.º 5
0
 public ActionResult Create(Category newCategory)
 {
     if (ModelState.IsValid)
     {
         _ctxCategory.Categories.Add(newCategory);
         _ctxCategory.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(newCategory));
 }
Exemplo n.º 6
0
        public void ProcessRequest(HttpContext context)
        {
            CategoryContext categoryContext = new CategoryContext();


            String userName = context.Request.QueryString["uname"].ToString();
            String url      = context.Request.QueryString["url"].ToString();
            String type     = context.Request.QueryString["type"].ToString();

            if (type.Equals("rss"))
            {
                String   ctyname  = context.Request.QueryString["ctyname"].ToString();
                Category category = categoryContext.Categories.Where(c => c.Name.ToString().Equals(ctyname)).FirstOrDefault();


                var    reader = XmlReader.Create(url);
                var    feed   = SyndicationFeed.Load(reader);
                String title  = feed.Title.Text.ToString();

                Rss rss = new Rss
                {
                    Name     = title,
                    UserName = userName,
                    Url      = url
                };

                category.Rsses.Add(rss);
                categoryContext.SaveChanges();
            }
            else if (type.Equals("essay"))
            {
                String    fvtname   = context.Request.QueryString["fvtname"].ToString();
                Favourite favourite = categoryContext.Favourites.Where(f => (f.UserName.ToString().Equals(userName) && f.Name.ToString().Equals(fvtname))).FirstOrDefault();

                List <String> tad         = getWebTitleAndDescription(url);
                String        title       = tad[0];
                String        description = tad[1];


                Essay essay = new Essay
                {
                    Url         = url,
                    Title       = title,
                    Description = description
                };

                favourite.Essays.Add(essay);
                categoryContext.SaveChanges();
            }



            //context.Response.ContentType = "text/plain";
            //context.Response.Write("");
        }
Exemplo n.º 7
0
        public ActionResult Create([Bind(Include = "IdCategory,Title")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Main", "Home"));
            }

            return(View(category));
        }
Exemplo n.º 8
0
        public ActionResult Create([Bind(Include = "Cat_id,Cat_title")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Exemplo n.º 9
0
 public ActionResult Create(Category category)
 {
     try
     {
         _context.Categories.Add(category);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         return(View(category));
     }
 }
Exemplo n.º 10
0
        public void ProcessRequest(HttpContext context)
        {
            CategoryContext categoryContext = new CategoryContext();
            String          str             = context.Request.QueryString["str"];
            String          str2            = context.Request.QueryString["uname"];
            String          type            = context.Request.QueryString["type"];

            if (type.Equals("cty"))
            {
                Category category = new Category
                {
                    //Id = categoryContext.Configs.ToList<Config>()[0].max_cty_id,
                    Name     = str,
                    UserName = str2
                };
                categoryContext.Categories.Add(category);
            }
            else if (type.Equals("fvt"))
            {
                Favourite favorite = new Favourite
                {
                    //Id = categoryContext.Configs.ToList<Config>()[0].max_cty_id,
                    Name     = str,
                    UserName = str2
                };
                categoryContext.Favourites.Add(favorite);
            }

            categoryContext.SaveChanges();
        }
Exemplo n.º 11
0
        public JsonResult InsertCategory(Category category)
        {
            using (CategoryContext entities = new CategoryContext())
            {
                entities.Categories.Add(category);
                entities.SaveChanges();
            }

            return(Json(category));
        }
        public ActionResult Create([Bind(Include = "title, is_published")] Category categoey)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    categoey.created_at  = DateTime.Now;
                    categoey.modified_at = DateTime.Now;
                    db.Categories.Add(categoey);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes. Try again.");
            }

            return(View(categoey));
        }
Exemplo n.º 13
0
 public ActionResult DeleteCategory(int prodID)
 {
     using (CategoryContext entities = new CategoryContext())
     {
         Category product = (from c in entities.Categories
                             where c.CategoryID == prodID
                             select c).FirstOrDefault();
         entities.Categories.Remove(product);
         entities.SaveChanges();
     }
     return(new EmptyResult());
 }
        /// <summary>
        /// I denne klasse opstilles der funktioner til at tilføje data til min database,
        /// når mit projekt startes. Dette bliver typisk kaldt for at 'Seed' en database.
        /// Jeg valgte at oprette en SeedData klasse så at der er noget data at teste med,
        /// frem for at mine API er tomme, og skal fyldes manuelt.
        /// </summary>
        /// <param name="serviceProvider"></param>
        public static void AddCategories(IServiceProvider serviceProvider)
        {
            ///<summary>
            /// Her specificeres hvilken service og context som skal bruges.
            /// IServiceProvider bruges til at hente vores context, som her er Category,
            /// som er påkrævet for at jeg kan tilføje nye dataobjekter.
            ///</summary>
            using (var context = new CategoryContext(
                       serviceProvider.GetRequiredService <DbContextOptions <CategoryContext> >()))
            {
                /// <summary>
                /// Vi bruger denne 'if' statement for at tjekke om der er nogen data elementer
                /// gemt via. vores context. Hvis der er, bliver de returneret.
                /// </summary>
                if (context.Categories.Any())
                {
                    return;
                }

                /// <summary>
                /// Her tilføjer jeg nye data elementer gennem min context.
                /// 'AddRange' lader mig tilføje flere elementer ad gangen,
                /// og vil så holde på dem indtil vi har gemt dem til databasen.
                /// </summary>
                context.Categories.AddRange(
                    new Category
                {
                    Name        = "Beverages",
                    Description = "Liquid beverages in various packaging. Includes juices, soft drinks, etc."
                },
                    new Category
                {
                    Name        = "Salty Snacks",
                    Description = "Bagged salty snackfoods. Includes various chips, nuts, etc."
                },
                    new Category
                {
                    Name        = "Frozen Vegetables",
                    Description = "Bagged frozen vegetable. Must be kept cool until used."
                },
                    new Category
                {
                    Name        = "Sweets",
                    Description = "Sweet baked goods and candy."
                }
                    );
                /// <summary>
                /// Her gemmer vi vores ændringer, så at vores elementer
                /// nu vil bliver tilføjet til databasen.
                /// </summary>
                context.SaveChanges();
            }
        }
Exemplo n.º 15
0
        public CategoryController(CategoryContext context)
        {
            _context = context;

            if (_context.GetCategories.Count() == 0)
            {
                _context.GetCategories.Add(new Category {
                    Name = "Beer"
                });
                _context.SaveChanges();
            }
        }
Exemplo n.º 16
0
        public CategoryController(CategoryContext context)
        {
            _context = context;

            if (_context.Category.Count() == 0)
            {
                _context.Category.Add(new Category {
                    Name = "Cat1"
                });
                _context.SaveChanges();
            }
        }
Exemplo n.º 17
0
        public JsonResult Insert([FromBody] Category item)
        {
            if (item != null)
            {
                try
                {
                    Category apointment = new Category
                    {
                        Name        = item.Name,
                        Description = item.Description,
                    };

                    var insertedItem = _context.Add <Category>(apointment);
                    _context.SaveChanges();
                    return(Json(insertedItem.Entity));
                }
                catch (Exception e)
                {
                    return(Json(e.Message));
                }
            }
            return(Json("Error"));
        }
        public CategoriesController(CategoryContext _context)
        {
            context = _context;

            if (context.Categories.Count() == 0)
            {
                context.Categories.Add(new Category
                {
                    Name = "Groceries"
                });
                context.Categories.Add(new Category
                {
                    Name = "Entertainment"
                });
                context.SaveChanges();
            }
        }
Exemplo n.º 19
0
        public ActionResult UpdateCategory(Category category)
        {
            using (CategoryContext entities = new CategoryContext())
            {
                Category updatedCategory = (from c in entities.Categories
                                            where c.CategoryID == category.CategoryID
                                            select c).FirstOrDefault();
                updatedCategory.CategoryName = category.CategoryName;
                entities.SaveChanges();
            }
            using (ProductContext entities = new ProductContext())
            {
                List <Product> updatedProduct = (from c in entities.Products
                                                 where c.CategoryID == category.CategoryID
                                                 select c).ToList();
                foreach (var p in updatedProduct)
                {
                    p.CategoryName = category.CategoryName;
                }
                entities.SaveChanges();
            }

            return(new EmptyResult());
        }
Exemplo n.º 20
0
 public void Delete(Category category)
 {
     category.Archived = true;
     categoryContext.SaveChanges();
 }
 public void Save()
 {
     _dbContext.SaveChanges();
 }
Exemplo n.º 22
0
        public static void Initialize(CategoryContext context)
        {
            if (!context.Types.Any())
            {
                context.Types.AddRange(Types.Select(f => f.Value));
            }

            context.SaveChanges();
            if (!context.Categories.Any())
            {
                context.Categories.AddRange(
                    new Category
                {
                    Name = "Еда",
                    Type = Types["Общие"]
                },
                    new Category
                {
                    Name = "Техника",
                    Type = Types["Общие"]
                },
                    new Category
                {
                    Name = "Билеты",
                    Type = Types["Командировки"]
                },
                    new Category
                {
                    Name = "Такси",
                    Type = Types["Командировки"]
                },
                    new Category
                {
                    Name = "Проживание",
                    Type = Types["Командировки"]
                },
                    new Category
                {
                    Name = "Питание",
                    Type = Types["Командировки"]
                },
                    new Category
                {
                    Name = "Аренда",
                    Type = Types["Корпоратив"]
                },
                    new Category
                {
                    Name = "Еда",
                    Type = Types["Корпоратив"]
                },
                    new Category
                {
                    Name = "Напитки",
                    Type = Types["Корпоратив"]
                },
                    new Category
                {
                    Name = "Алкоголь",
                    Type = Types["Корпоратив"]
                }
                    );
            }

            context.SaveChanges();
            if (!context.Users.Any())
            {
                context.Users.AddRange(
                    new User
                {
                    Name       = "Дмитрий",
                    Surname    = "Рогожников",
                    Middlename = "Юрьевич"
                },
                    new User
                {
                    Name       = "Семен",
                    Surname    = "Щелков",
                    Middlename = "Алексеевич"
                },
                    new User
                {
                    Name       = "Василий",
                    Surname    = "Пупкин",
                    Middlename = null
                });
            }

            context.SaveChanges();

            if (!context.Bills.Any())
            {
                var users = context.Users;
                context.Bills.AddRange(
                    new Bill
                {
                    TotalSum = 0,
                    User     = users.FirstOrDefault(f => f.Id == 1)
                },
                    new Bill
                {
                    TotalSum = 0,
                    User     = users.FirstOrDefault(f => f.Id == 2)
                },
                    new Bill
                {
                    TotalSum = 0,
                    User     = users.FirstOrDefault(f => f.Id == 3)
                }
                    );
            }

            context.SaveChanges();

            if (!context.Expenses.Any())
            {
                var bills = context.Bills;
                context.Expenses.AddRange(
                    new Expense
                {
                    Bill        = bills.FirstOrDefault(f => f.UserId == 1),
                    Type        = Types["Общие"],
                    Category    = context.Categories.FirstOrDefault(f => f.Type == Types["Общие"] && f.Name == "Еда"),
                    Sum         = 12300,
                    Paid        = 0,
                    Description = "Sample Desctiption for this",
                    Cheque      = "Link to cheque 1"
                },
                    new Expense
                {
                    Bill        = bills.FirstOrDefault(f => f.UserId == 1),
                    Type        = Types["Корпоратив"],
                    Category    = context.Categories.FirstOrDefault(f => f.Type == Types["Корпоратив"] && f.Name == "Алкоголь"),
                    Sum         = 1300,
                    Paid        = 0,
                    Description = "Sample Desctiption for PIVO",
                    Cheque      = "Link to cheque 2"
                },
                    new Expense
                {
                    Bill     = bills.FirstOrDefault(f => f.UserId == 2),
                    Type     = Types["Командировки"],
                    Category =
                        context.Categories.FirstOrDefault(f => f.Type == Types["Командировки"] && f.Name == "Билеты"),
                    Sum         = 15236.31,
                    Paid        = 236.31,
                    Description = "Sample Desctiption for командировки",
                    Cheque      = "Link to cheque 1"
                },
                    new Expense
                {
                    Bill        = bills.FirstOrDefault(f => f.UserId == 3),
                    Type        = Types["Общие"],
                    Category    = context.Categories.FirstOrDefault(f => f.Type == Types["Общие"] && f.Name == "Техника"),
                    Sum         = 322.28,
                    Paid        = 0,
                    Description = "Sample Description for general",
                    Cheque      = "Link to cheque 1"
                }
                    );
                context.SaveChanges();
            }
        }
Exemplo n.º 23
0
        public ProductsController(CategoryContext context)
        {
            db = context;

            //db.Categories.Add(new Category { CategoryName = "Sneakers" });
            //db.Categories.Add(new Category { CategoryName = "Sliders" });
            //db.Categories.Add(new Category { CategoryName = "Shoes" });
            //db.Categories.Add(new Category { CategoryName = "Boots" });

            db.Products.Add(new Product {
                Title = "Nike Free", Subtitle = "Nike Air Max", Price = 139.99, Description = dummyText, Image = "assets/images/nike.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Jordan", Subtitle = "Nike Air Max", Price = 239.99, Description = dummyText, Image = "assets/images/air1.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Old Scool", Subtitle = "VANS", Price = 59.99, Description = dummyText, Image = "assets/images/vans.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Supreme", Subtitle = "Nike Air Max", Price = 559.99, Description = dummyText, Image = "assets/images/air3.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Superstar", Subtitle = "Adidas", Price = 129.99, Description = dummyText, Image = "assets/images/adidas.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Air Force", Subtitle = "Nike", Price = 169.99, Description = dummyText, Image = "assets/images/nike2.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Nike Run", Subtitle = "Nike", Price = 229.99, Description = dummyText, Image = "assets/images/nike3.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Jordan Red", Subtitle = "Nike Air Max", Price = 159.99, Description = dummyText, Image = "assets/images/air2.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Nike R", Subtitle = "Nike", Price = 99.99, Description = dummyText, Image = "assets/images/nike4.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Puma Skate", Subtitle = "Puma", Price = 89.99, Description = dummyText, Image = "assets/images/puma.png", CategoryName = "Sneakers"
            });
            db.Products.Add(new Product {
                Title = "Jordan Gold", Subtitle = "Nike Air Max", Price = 459.99, Description = dummyText, Image = "assets/images/air4.png", CategoryName = "Sneakers"
            });

            db.Products.Add(new Product {
                Title = "Nike Free", Subtitle = "Nike Air Max", Price = 139.99, Description = dummyText, Image = "assets/images/slid1.png", CategoryName = "Sliders"
            });
            db.Products.Add(new Product {
                Title = "Jordan", Subtitle = "Nike Air Max", Price = 239.99, Description = dummyText, Image = "assets/images/slid2.png", CategoryName = "Sliders"
            });
            db.Products.Add(new Product {
                Title = "Old Scool", Subtitle = "VANS", Price = 59.99, Description = dummyText, Image = "assets/images/slid3.png", CategoryName = "Sliders"
            });

            db.Products.Add(new Product {
                Title = "Supreme", Subtitle = "Nike Air Max", Price = 559.99, Description = dummyText, Image = "assets/images/shoes1.png", CategoryName = "Shoes"
            });
            db.Products.Add(new Product {
                Title = "Superstar", Subtitle = "Adidas", Price = 129.99, Description = dummyText, Image = "assets/images/shoes2.png", CategoryName = "Shoes"
            });
            db.Products.Add(new Product {
                Title = "Air Force", Subtitle = "Nike", Price = 169.99, Description = dummyText, Image = "assets/images/shoes3.png", CategoryName = "Shoes"
            });
            db.Products.Add(new Product {
                Title = "Nike Run", Subtitle = "Nike", Price = 229.99, Description = dummyText, Image = "assets/images/shoes4.png", CategoryName = "Shoes"
            });

            db.Products.Add(new Product {
                Title = "Jordan Red", Subtitle = "Nike Air Max", Price = 159.99, Description = dummyText, Image = "assets/images/boots1.png", CategoryName = "Boots"
            });
            db.Products.Add(new Product {
                Title = "Nike R", Subtitle = "Nike", Price = 99.99, Description = dummyText, Image = "assets/images/boots2.png", CategoryName = "Boots"
            });
            db.Products.Add(new Product {
                Title = "Puma Skate", Subtitle = "Puma", Price = 89.99, Description = dummyText, Image = "assets/images/boots3.png", CategoryName = "Boots"
            });
            db.Products.Add(new Product {
                Title = "Jordan Gold", Subtitle = "Nike Air Max", Price = 459.99, Description = dummyText, Image = "assets/images/boots4.png", CategoryName = "Boots"
            });

            db.SaveChanges();
        }