Ejemplo n.º 1
0
        public IActionResult Add(Payment payment)
        {
            var result = _paymentManager.Add(payment);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
        public IActionResult AddOrUpdate(int id, [FromBody] PaymentDto model)
        {
            if (ModelState.IsValid)
            {
                if (id > 0)
                {
                    var retriveItem = _iPaymentManager.GetById(id);
                    if (retriveItem == null)
                    {
                        return(BadRequest(new { error = "Can not found Data!!" }));
                    }

                    retriveItem.Amount = model.Amount;
                    var isUpdate = _iPaymentManager.Update(retriveItem);
                    if (isUpdate)
                    {
                        return(Ok(retriveItem));
                    }

                    return(BadRequest(new { error = "Update Failed!!" }));
                }
                else
                {
                    var paymentItem = _iMapper.Map <Payment>(model);
                    var isAdded     = _iPaymentManager.Add(paymentItem);
                    if (isAdded)
                    {
                        return(Ok(paymentItem));
                    }

                    return(BadRequest(new { error = "Failed To Add!!" }));
                }
            }

            return(BadRequest(new { error = "Model is not Valid!!" }));
        }