Exemple #1
0
        public async Task <ActionResult> PutAsync(int id, [FromBody] Disbursements 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"
                }));
            }
        }
Exemple #2
0
        public async Task <ActionResult> PostAsync([FromBody] Disbursements item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            try
            {
                var exist = await service.GetAsync(x => x.transactionreference == item.transactionreference);

                if (exist != null)
                {
                    return(Conflict(new Response()
                    {
                        Status = false, Description = "Duplicate record"
                    }));
                }
                var result = await service.AddAsync(item);

                if (result)
                {
                    var newitem = await service.GetAsync(x => x.transactionreference == item.transactionreference);

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