Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        public RequestTypeResponse ToRequestTypeResponse(RequestTypeEntity requestTypeEntity)
        {
            if (requestTypeEntity == null)
            {
                return(null);
            }

            return(new RequestTypeResponse
            {
                Id = requestTypeEntity.Id,
                Type = requestTypeEntity.Type,
            });
        }