Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,Name")] Category category)
        {
            if (id != category.CategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(long id, [Bind("ComponentId,ComponentTypeId,ComponentNumber,SerialNo,Status,AdminComment,UserComment,CurrentLoanInformationId")] Component component)
        {
            if (id != component.ComponentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(component);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComponentExists(component.ComponentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(component));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(long id, ComponentType componentType, IFormFile imageFile)
        {
            if (id != componentType.ComponentTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (imageFile.Length > 0)
                    {
                        var stream    = imageFile.OpenReadStream();
                        var bitmap    = FreeImageBitmap.FromStream(stream);
                        var thumbnail = bitmap.GetThumbnailImage(1000, true);

                        using (var m = new MemoryStream())
                        {
                            bitmap.Save(m, format: bitmap.ImageFormat);
                            componentType.Image.ImageData = m.ToArray();
                        }
                        using (var m = new MemoryStream())
                        {
                            thumbnail.Save(m, format: FREE_IMAGE_FORMAT.FIF_JPEG);
                            componentType.Image.Thumbnail = m.ToArray();
                        }
                    }

                    _context.Update(componentType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComponentTypeExists(componentType.ComponentTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(componentType));
        }