예제 #1
0
        public async Task <ActionResult <Character> > CreateCharacter([FromBody] Character character)
        {
            _context.Add(character);
            await _context.SaveChangesAsync();

            return(Ok());
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("ID,ImageUrl,Name,Description,Price,RamAndStorage,BatteryCapacity")] LaptopModel laptopModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(laptopModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(laptopModel));
        }
예제 #3
0
        public async Task <IActionResult> Create(OrderModel orderModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orderModel));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("ID,NAME,DSCRIP")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("Id,Diametru,Sarja,Furnizor,Calitate,IsDatAfara,IsRetur,IsRebut,DataOraLaminare")] Blum blum)
        {
            if (ModelState.IsValid)
            {
                _context.Add(blum);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(blum));
        }
예제 #6
0
        public async Task <IActionResult> ImportFile(List <IFormFile> files)
        {
            // Verificam daca lista de fisiera incarcata  are 0 elemente si returnam msj
            if (files.Count == 0)
            {
                ViewBag.Hidden = "";
                ViewBag.Mesaj  = "Fisierul nu s-a incarcat";
                return(View());
            }

            // Cream fisier din primul lelement din lista de fisiere
            IFormFile formFile = files[0];

            // Verificam daca fisierul are extensia .xlsx
            if (!formFile.FileName.EndsWith(".xlsx"))
            {
                ViewBag.Hidden = "";
                ViewBag.Mesaj  = "Fisierul nu are extensia .xlsx!";
                return(View());
            }

            //Cream lista de blumuri din fisier excel
            List <Blum> listaBlumuri = await Auxiliar.GetBlumsListFromExcelFileBySarjaAsync(formFile);

            // Actualizam baza de date cu lista de blumuri din fisier
            if (listaBlumuri != null)
            {
                foreach (Blum item in listaBlumuri)
                {
                    _context.Add(item);
                    _context.SaveChanges();
                }
            }

            // Redirection la Index
            return(RedirectToAction("Index", "Home"));
        }