Ejemplo n.º 1
0
 public bool UpdateExpense(UpdateExpenseVm newExpense)
 {
     try
     {
         if (newExpense.Id < 0 || newExpense.Id == 0)
         {
             return(false);
         }
         else if (newExpense == null)
         {
             return(false);
         }
         else
         {
             var data = _baseRepository.GetById <Expense>(newExpense.Id);
             data.ValueOfExpense   = newExpense.ValueOfExpense;
             data.ReasonForExpense = newExpense.ReasonForExpense;
             data.Created          = DateTime.ParseExact(newExpense.Created, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
             data.Modified         = DateTime.Now;
             return(_baseRepository.Update(data));
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message + "=>" + e.InnerException + "||" + e.StackTrace);
         return(false);
     }
 }
        public async Task <ResultModel> UpdateExpense(UpdateExpenseVm updateExpenseVm)
        {
            try
            {
                if (updateExpenseVm.ExpenseId > 0)
                {
                    var entity = new Expense
                    {
                        ExpenseId        = updateExpenseVm.ExpenseId,
                        ExpenseTypeId    = updateExpenseVm.ExpenseTypeId,
                        ExpenseSubTypeId = updateExpenseVm.ExpenseSubTypeId,
                        BillNo           = updateExpenseVm.BillNo,
                        Quantity         = updateExpenseVm.Quantity,
                        BillingDate      = updateExpenseVm.BillingDate,
                        BillingAmount    = updateExpenseVm.BillingAmount,
                        VehicleId        = updateExpenseVm.VehicleId,

                        UpdateBy   = _currentUserService.UserId,
                        UpdateDate = _dateTime.Now,
                    };

                    _context.EXPENSE.Update(entity);
                    await _context.SaveChangesAsync();

                    return(new ResultModel
                    {
                        Result = true,
                        Message = NotificationConfig.UpdateSuccessMessage($"{updateExpenseVm.BillNo}"),
                        Id = entity.ExpenseId.ToString()
                    });
                }


                else
                {
                    return(new ResultModel {
                        Result = false, Message = NotificationConfig.NotFoundMessage($"{updateExpenseVm.BillNo} ")
                    });
                }
            }

            catch (Exception)
            {
                return(new ResultModel {
                    Result = false, Message = NotificationConfig.UpdateErrorMessage($"{updateExpenseVm.BillNo}")
                });
            }
        }
Ejemplo n.º 3
0
 public IActionResult UpdateExpense([FromBody] UpdateExpenseVm expense)
 {
     try
     {
         if (expense.Id < 0 || expense.Id == 0)
         {
             return(Json(ResponseData.SendFailMsg("Kindly provide a valid Id parameter")));
         }
         if (expense == null)
         {
             return(Json(ResponseData.SendFailMsg("Kindly Pass a Valid Expense Object")));
         }
         return(_expenseService.UpdateExpense(expense) ? Json(ResponseData.SendSuccessMsg("Successfully updated record"))
             : Json(ResponseData.SendFailMsg($"Unable to updated record")));
     }
     catch (Exception e)
     {
         _logger.LogError(e.Message + "=>" + e.InnerException + "||" + e.StackTrace);
         return(Json(ResponseData.SendExceptionMsg(e)));
     }
 }