Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,ProductId")] ProductCategory productCategory)
        {
            if (id != productCategory.CategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductCategoryExists(productCategory.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", productCategory.CategoryId);
            ViewData["ProductId"]  = new SelectList(_context.Products, "Id", "Id", productCategory.ProductId);
            return(View(productCategory));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Name,Id,CreatedDate,ModifiedDate")] Stock stock)
        {
            if (id != stock.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    stock.ModifiedDate = DateTime.Now.ToUniversalTime();
                    _context.Update(stock);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StockExists(stock.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(stock));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Name,ParentId,Id,CreatedDate,ModifiedDate")] Category category)
        {
            if (id != category.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    category.ModifiedDate = DateTime.UtcNow;
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Url,ProductId,Id,CreatedDate,ModifiedDate,ImageFile")] Image image)
        {
            if (id != image.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var product = _context.Products.Find(image.ProductId);
                    image.Url = await _commonServices.EditImage(image.ImageFile, image.Url, "/images/Products/" + product.Name);

                    image.ModifiedDate = DateTime.Now.ToUniversalTime();
                    _context.Update(image);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ImageExists(image.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "DisplayName", image.Product.DisplayName);
            return(View(image));
        }
        public async Task <IActionResult> Edit(int id, [Bind("FirstName,LastName,Phone,Email,Username,Password,Note,Age,Gender,Address,City,UserType,SubsidiaryTotalProduct,AgentName,SupplyCode,ImageFile,SupplyName,Salary,Id,CreatedDate,ModifiedDate,Avatar")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    user.Avatar = await _commonServices.EditImage(user.ImageFile, user.Avatar, "/images/People");

                    user.ModifiedDate = DateTime.Now.ToUniversalTime();
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        /// <summary>
        /// Agrega un libro nuevo sin pasar por la importacion
        /// </summary>
        /// <param name="nuevo"></param>
        public void AgregarLibro(Libro nuevo, bool save = true)
        {
            //_ctx.Debug();

            if (_ctx.Find <Libro>(nuevo.ID_Real) != null)
            {
                _ctx.Update(nuevo);
            }
            else
            {
                _ctx.Add(nuevo);
            }

            //_ctx.Debug();

            if (save)
            {
                _ctx.SaveChanges();
            }
        }