public async Task <IActionResult> Create(RequestTypeEntity requestTypeEntity) { if (ModelState.IsValid) { _context.Add(requestTypeEntity); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "Already there is a record with the same name."); } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); } } } return(View(requestTypeEntity)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Type")] RequestTypeEntity requestTypeEntity) { if (id != requestTypeEntity.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(requestTypeEntity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RequestTypeEntityExists(requestTypeEntity.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(requestTypeEntity)); }
public async Task <IActionResult> PutRequestTypeEntity([FromRoute] int id, [FromBody] RequestTypeEntity requestTypeEntity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != requestTypeEntity.Id) { return(BadRequest()); } _context.Entry(requestTypeEntity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RequestTypeEntityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostRequestTypeEntity([FromBody] RequestTypeEntity requestTypeEntity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.RequestTypes.Add(requestTypeEntity); await _context.SaveChangesAsync(); return(CreatedAtAction("GetRequestTypeEntity", new { id = requestTypeEntity.Id }, requestTypeEntity)); }
public RequestTypeResponse ToRequestTypeResponse(RequestTypeEntity requestTypeEntity) { if (requestTypeEntity == null) { return(null); } return(new RequestTypeResponse { Id = requestTypeEntity.Id, Type = requestTypeEntity.Type, }); }