/// <summary>
        /// Aplica reglas de negocio a la lista de origen e intenta guardar la informacion faltante en la base de datos
        /// Solo incorpora libros que NO EXISTEN
        /// </summary>
        /// <param name="lista"></param>
        public void ExportarListaDeLibros(IEnumerable <Libro> lista)
        {
            //  ver si el libro ya existe...(por ISBN13)
            //  si el ISBN es null lo agrego sin mas...
            //  si no existe lo agrego

            foreach (Libro libro in lista)
            {
                //if (!_ctx.Libros.Any(lib => lib.ISBN13 == libro.ISBN13))
                if (!_ctx.Set <Libro>().Any(lib => lib.ISBN13 == libro.ISBN13))
                {
                    //  podriamos setear la PK desde nuestra aplicacion!
                    //
                    //  nuevo.ID_Real = Guid.NewGuid();
                    //
                    _ctx.Add <Libro>(libro);
                    //  _ctx.Libros.Add(libro);
                }
                else
                {
                    _logger.LogWarning("Se intento ingresar un elemento existente {libro}", libro);
                }
            }
            //  guardamos la operacion TOTAL
            //
            _ctx.SaveChanges();
        }
        public async Task <IActionResult> Create([Bind("Name,Id,CreatedDate,ModifiedDate")] Stock stock)
        {
            if (ModelState.IsValid)
            {
                stock.CreatedDate = stock.ModifiedDate = DateTime.Now.ToUniversalTime();
                _context.Add(stock);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(stock));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Name,ParentId,Id,CreatedDate,ModifiedDate")] Category category)
        {
            if (ModelState.IsValid)
            {
                category.CreatedDate = category.ModifiedDate = DateTime.UtcNow;
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("ShortName,FullName,Id,CreatedDate,ModifiedDate")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                brand.ModifiedDate = brand.CreatedDate = DateTime.Now.ToUniversalTime();
                _context.Add(brand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brand));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("CategoryId,ProductId")] ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", productCategory.Category.Name);
            ViewData["ProductId"]  = new SelectList(_context.Products, "Id", "Name", productCategory.Product.Name);
            return(View(productCategory));
        }
        public async Task <IActionResult> Create([Bind("Url,ProductId,Id,CreatedDate,ModifiedDate,ImageFile")] Image image)
        {
            if (ModelState.IsValid)
            {
                var product = _context.Products.Find(image.ProductId);
                image.Url = await _commonServices.CreateImage(image.ImageFile, image.Url, "/images/Products/" + product.Name);

                image.CreatedDate = image.ModifiedDate = DateTime.UtcNow;
                _context.Add(image);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "DisplayName", image.Product.DisplayName);
            return(View(image));
        }
        public async Task <IActionResult> Create([Bind("FirstName,LastName,Phone,Email,Username,Password,Note,Age,Gender,Address,City,UserType,SubsidiaryTotalProduct,AgentName,SupplyCode,ImageFile,SupplyName,Salary,Id,CreatedDate,ModifiedDate")] User user)
        {
            if (ModelState.IsValid)
            {
                //Save image to wwwroot/image
                //string wwwRootPath = _hostEnvironment.WebRootPath;
                //string fileName = Path.GetFileNameWithoutExtension(user.ImageFile.FileName);
                //string extension = Path.GetExtension(user.ImageFile.FileName);
                user.Avatar = await _commonServices.CreateImage(user.ImageFile, user.Avatar, "/images/People");

                //Insert record
                user.CreatedDate = user.ModifiedDate = DateTime.Now.ToUniversalTime();
                _context.Add(user);
                await _context.SaveChangesAsync();

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