private void Seed()
        {
            using (var context = new ItemsContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.Add(new Item {
                    Id = 1, Name = "El_1", Price = 5, Description = "Opis"
                });
                context.Add(new Item {
                    Id = 2, Name = "El_2", Price = 15, Description = "Opis - El_2"
                });
                context.Add(new Item {
                    Id = 3, Name = "A", Price = 35, Description = "Opis - A"
                });
                context.Add(new Item {
                    Id = 5, Name = "B", Price = 55, Description = "Opis - B"
                });
                context.Add(new Item {
                    Id = 6, Name = "C", Price = 11, Description = "Opis - C"
                });
                context.Add(new Item {
                    Id = 11, Name = "D", Price = 102, Description = "Opis - D"
                });
                context.Add(new Item {
                    Id = 12, Name = "D1", Price = 85, Description = "Opis - D1"
                });

                context.SaveChanges();
            }
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("ID,Product,Price")] Items items)
        {
            if (ModelState.IsValid)
            {
                _context.Add(items);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(items));
        }
 public IActionResult SaveElement(Item element)
 {
     try
     {
         _context.Add(element);
         return(Ok(element));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Exemple #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,CategoryId,GenderId,Features,Image")] Item item)
        {
            var catId  = Request.Form["CategoryId"];
            var CatObj = _categoryContext.AllCategories.FirstOrDefault(x => x.Id == catId);

            var genId  = Request.Form["GenderId"];
            var genObj = _gendersContext.AllGenders.FirstOrDefault(x => x.Id == genId);


            var fDesc    = Request.Form["Features.Description"];
            var fCountry = Request.Form["Features.Country"];
            var fMater   = Request.Form["Features.Material"];
            var fSize    = Request.Form["Features.Size"];
            var fColor   = Request.Form["Features.Color"];

            if (ModelState.IsValid)
            {
                item.Features.Id = item.Id + "fe";
                item.CategoryId  = catId;
                item.GenderId    = genId;

                /*
                 * item.Features.Country = fCountry;
                 * item.Features.Description = fDesc;
                 * item.Features.Material = fMater;
                 * item.Features.Id = item.Id+"fe";
                 * item.Features.Color = fColor;*/

                /*
                 * item.Category.Id = CatObj.Id.ToString();
                 * item.Gender.Id = genObj.Id.ToString();
                 *
                 * item.Category.Name = CatObj.Name.ToString();
                 * item.Gender.Name = genObj.Name.ToString();*/

                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(item));
        }
        public async Task <IActionResult> Create([Bind("IdModel,BitchNameModel,NumberModel,TiTDescriptionModel,ProfilePictureModel")] ListViewModel item)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(item);

                Item listItem = new Item
                {
                    BitchName      = item.BitchNameModel,
                    ProfilePicture = uniqueFileName,
                    Number         = item.NumberModel,
                    TiTDescription = item.TiTDescriptionModel
                };

                _context.Add(listItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(item));
        }
Exemple #6
0
 public void Add(Item item)
 {
     _appDbContext.Add(item);
 }