Ejemplo n.º 1
0
        public IList <ExpenseObject> GetAllExpenseSheet()
        {
            try
            {
                List <ExpenseObject> exObjecttList = new List <ExpenseObject>();
                foreach (Expense source in (IEnumerable <Expense>)expenseRepo.GetAll())
                {
                    ExpenseObject exObject = _Mapper.Map <Expense, ExpenseObject>(source);
                    exObjecttList.Add(exObject);
                }

                return((IList <ExpenseObject>)exObjecttList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public async Task <IActionResult> Put(ExpenseObject obj)
 {
     try
     {
         if (obj.Id != Guid.Empty)
         {
             if (await _service.UpdateExpense(obj))
             {
                 return(Ok());
             }
             return(BadRequest());
         }
         return(BadRequest());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public async Task <ActionResult <Expense> > Delete(ExpenseObject Obj)
 {
     try
     {
         if (Obj.Id != Guid.Empty)
         {
             if (await _service.RemoveExpense(Obj))
             {
                 return(Ok());
             }
             return(BadRequest());
         }
         return(BadRequest());
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 4
0
 public Task <bool> RemoveExpense(ExpenseObject obj)
 {
     return(Task.Run(() =>
     {
         try
         {
             if (obj.Id != Guid.Empty)
             {
                 expenseRepo.Delete(obj.Id);
             }
             expenseRepo.UnitofWork.Commit();
             return true;
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }));
 }
        public async Task <ActionResult <Expense> > Post(ExpenseObject Obj)
        {
            try
            {
                if (Obj.Id == Guid.Empty)
                {
                    Obj.Id = await _service.CreateExpense(Obj);

                    if (Obj.Id != Guid.Empty)
                    {
                        return(Ok(Obj.Id));
                    }
                    return(BadRequest());
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
        public Task <Guid> CreateExpense(ExpenseObject obj)
        {
            return(Task.Run(() =>
            {
                try
                {
                    if (obj.Id == Guid.Empty)
                    {
                        var dataObj = new MapperConfiguration(ap =>
                        {
                            ap.CreateMap <ExpenseObject, Expense>();
                        });

                        IMapper iMapper = dataObj.CreateMapper();

                        var source = new Expense();

                        source.Id = IdentityGenerator.NewSequentialGuid();
                        source.Amount = obj.Amount;
                        source.Date = obj.Date;
                        source.Details = obj.Details;

                        expenseRepo.Add(source);
                        expenseRepo.UnitofWork.Commit();

                        return source.Id;
                    }

                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }));
        }
Ejemplo n.º 7
0
        public Task <bool> UpdateExpense(ExpenseObject obj)
        {
            return(Task.Run(() =>
            {
                try
                {
                    Expense entity = _Mapper.Map <ExpenseObject, Expense>(obj);

                    if (obj.Id != Guid.Empty)
                    {
                        expenseRepo.Update(entity);
                    }
                    expenseRepo.UnitofWork.Commit();

                    return true;
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException(ex.Message);
                }
            }));
        }