public async Task <IEnumerable <ReportDTO> > GetCategoriesWithExpenses(string filterByYear, string userId) { var items = await _db.Categories.GetCategoriesWithExpenses(filterByYear, userId); var categories = new List <ReportDTO>(); foreach (var i in items) { var category = new ReportDTO { Id = i.Id, Name = i.Name }; foreach (var item in i.Expenditures) { var expense = new ExpenditureDTO { Id = item.Id, Comment = item.Comment, Cost = item.Cost, ExpenseTime = item.ExpenseTime, CategoryName = i.Name }; category.Expenses.Add(expense); } categories.Add(category); } return(categories); }
public static Expenditure TDOtoDAL(ExpenditureDTO expenditure) { return(new Expenditure() { Amount = expenditure.Amount, Purpose = expenditure.Purpose, Date = expenditure.Date, Receives = expenditure.Receives, Way_of_payment = expenditure.Way_of_payment, NameStatus = expenditure.NameStatus }); }
public ActionResult <ExpenditureDTO> UpdateExpenditure([FromBody] ExpenditureDTO ex) { try { ExpenditureBL.updateExpenditure(ex); } catch (Exception e) { return(BadRequest(e.ToString())); } return(Ok()); }
public static ExpenditureDTO DALtoDTO(Expenditure expenditure) { ExpenditureDTO expenditureNew = new ExpenditureDTO() { Id = expenditure.Id, Amount = expenditure.Amount, Date = (DateTime)expenditure.Date, Purpose = expenditure.Purpose, Receives = expenditure.Receives, NameStatus = expenditure.NameStatus, Way_of_payment = expenditure.Way_of_payment, Status = expenditure.NameStatus != null?StatusBL.GetByName(expenditure.NameStatus) : null }; return(expenditureNew); }
static public ExpenditureDTO GetByID(int id) { ExpenditureDTO exDTO = new ExpenditureDTO(); using (SuperGmachEntities db = new SuperGmachEntities()) { try { var e = db.Expenditure.FirstOrDefault(exp => exp.Id == id); exDTO = ExpenditureConvert.DALtoDTO(e); } catch (Exception ex) { throw ex; } } return(exDTO); }
public async Task <IEnumerable <ExpenditureDTO> > GetExpenditures(DateTime?startDate, DateTime?endDate, string userId) { var expenditures = new List <ExpenditureDTO>(); var data = await _db.Expenditures.GetExpenditures(startDate, endDate, userId); foreach (var d in data) { var expenditure = new ExpenditureDTO { Id = d.Id, ExpenseTime = d.ExpenseTime, Cost = d.Cost, Comment = d.Comment, CategoryName = d.Category.Name }; expenditures.Add(expenditure); } return(expenditures); }
public IHttpActionResult Get(int id) { try { var result = _expenditureService.Get(id); ExpenditureDTO expenditureDTO = ExpenditureDTO.From(result); return(Ok(expenditureDTO)); } catch (Exception ex) { if (ex.InnerException == null) { return(Content(HttpStatusCode.InternalServerError, ex.Message)); } else { return(Content(HttpStatusCode.InternalServerError, ex.InnerException.Message)); } } }
static public void AddExpenditure(ExpenditureDTO Expenditure) { using (SuperGmachEntities db = new SuperGmachEntities()) { try { Expenditure e = ExpenditureConvert.TDOtoDAL(Expenditure); db.Expenditure.Add(e); //fundId 1 is for the main fund if (Expenditure.NameStatus == "performed") { FundBL.Subtract_Balance(Expenditure.Amount, "1"); } db.SaveChanges(); } catch (Exception e) { throw e; } } }
public static void updateExpenditure(ExpenditureDTO expenditure) { using (SuperGmachEntities db = new SuperGmachEntities()) { try { Expenditure update_expenditure = db.Expenditure.FirstOrDefault(e => e.Id == expenditure.Id); if (update_expenditure != null) { update_expenditure.Amount = expenditure.Amount; update_expenditure.Date = expenditure.Date; //update_expenditure.future_date = expenditure.future_date; update_expenditure.Purpose = expenditure.Purpose; update_expenditure.Receives = expenditure.Receives; ///chack if its became performed if (expenditure.NameStatus != update_expenditure.NameStatus) { if (expenditure.NameStatus == "performed") { FundBL.Subtract_Balance(expenditure.Amount); } else { ///check if it was performed and change to canceled if (expenditure.NameStatus == "canceled" && update_expenditure.NameStatus == "performed") { FundBL.AddBalance(expenditure.Amount); } } update_expenditure.NameStatus = expenditure.NameStatus; } db.SaveChanges(); } } catch (Exception ex) { throw ex; } } }
public async Task <ExpenditureDTO> GetExpenditure(int?id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } var item = await _db.Expenditures.GetExpenditure(id); if (item == null) { throw new NullReferenceException(); } var expenditure = new ExpenditureDTO { Id = item.Id, ExpenseTime = item.ExpenseTime, Cost = item.Cost, Comment = item.Comment, CategoryName = item.Category.Name }; return(expenditure); }
public IHttpActionResult Get([FromUri] ExpenditureListParameter param) { try { if (ModelState.IsValid) { IList <Expenditure> expenditures = _expenditureService.GetAll().ToList(); if (param.IsPagination()) { string keyword = string.Empty; string field = string.Empty; param.Validate(); keyword = param.Search; field = param.SearchBy; int skip = 0; if (param.PageNo > 0) { skip = (param.PageNo - 1) * param.PageSize; } int totalRows = _expenditureService.GetAll().Count(); var totalPage = totalRows / param.PageSize; var totalPages = (int)Math.Ceiling((double)totalRows / param.PageSize); if (totalPages < 0) { totalPages = 0; } var result = expenditures.Skip(skip).Take(param.PageSize).ToList(); IList <ExpenditureDTO> colls = ExpenditureDTO.From(result); PaginationDTO page = new PaginationDTO(); page.PageCount = totalPages; page.PageNo = param.PageNo; page.PageSize = param.PageSize; page.results = colls; return(Ok(page)); } else { IList <ExpenditureDTO> dto = ExpenditureDTO.From(expenditures); return(Ok(dto)); } } else { string errorResult = string.Join(" ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)); return(Content(HttpStatusCode.BadRequest, errorResult)); } } catch (Exception ex) { if (ex.InnerException == null) { return(Content(HttpStatusCode.InternalServerError, ex.Message)); } else { return(Content(HttpStatusCode.InternalServerError, ex.InnerException.Message)); } } }