public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] TypeOfDocumentEntity typeOfDocumentEntity)
        {
            if (id != typeOfDocumentEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Update(typeOfDocumentEntity);
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "There is already that type of document");
                    }
                }
            }
            return(View(typeOfDocumentEntity));
        }
Exemplo n.º 2
0
        public TypeOfDocumentResponse ToTypeResponse(TypeOfDocumentEntity typeOfDocumentEntity)
        {
            if (typeOfDocumentEntity == null)
            {
                return(null);
            }

            return(new TypeOfDocumentResponse
            {
                Id = typeOfDocumentEntity.Id,
                Name = typeOfDocumentEntity.Name
            });
        }
        // GET: TypeOfDocuments/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TypeOfDocumentEntity typeOfDocumentEntity = await _context.TypeOfDocuments.FindAsync(id);

            if (typeOfDocumentEntity == null)
            {
                return(NotFound());
            }
            return(View(typeOfDocumentEntity));
        }
        // GET: TypeOfDocuments/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TypeOfDocumentEntity typeOfDocumentEntity = await _context.TypeOfDocuments
                                                        .FirstOrDefaultAsync(m => m.Id == id);

            if (typeOfDocumentEntity == null)
            {
                return(NotFound());
            }

            _context.TypeOfDocuments.Remove(typeOfDocumentEntity);
            await _context.SaveChangesAsync();

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