Ejemplo n.º 1
0
        public async Task <ActionResult> PutAsync(int id, [FromBody] AppRepayments item)
        {
            if (!ModelState.IsValid || id != item.id)
            {
                return(BadRequest());
            }
            try
            {
                var exist = await service.GetByIdAsync(id);

                if (exist != null)
                {
                    var result = await service.UpdateAsync(item);

                    return(result ? Ok(item) : StatusCode(500, new Response()
                    {
                        Status = false, Description = "Error updating record"
                    }));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(StatusCode(500, new Response()
                {
                    Status = false, Description = "System error"
                }));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> PostAsync([FromBody] AppRepayments item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            try
            {
                var result = await service.AddAsync(item);

                if (result)
                {
                    return(StatusCode(201, item));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                return(StatusCode(500, new Response()
                {
                    Status = false, Description = "System error"
                }));
            }
        }