public BillsStat GetAllBillsStat() { BillsStat billsStat = new BillsStat(); billsStat.TotalCount = _billRepository.All().Count(); billsStat.PayedCount = _billRepository.All().Count(bill => bill.WasPayed); billsStat.PayedSum = _billRepository.All().Where(bill => bill.WasPayed).Sum(bill => bill.Sum); billsStat.TotalSum = _billRepository.All().Sum(bill => bill.Sum); billsStat.UnpayedCount = billsStat.TotalCount - billsStat.PayedCount; billsStat.UnpayedSum = billsStat.TotalSum - billsStat.PayedSum; return(billsStat); }
public HttpResponseMessage Bills() { HttpResponseMessage response; try { BillsStat billsStat = queryBuilder .For <BillsStat>() .With(new EmptyCriterion()); response = Request.CreateResponse(HttpStatusCode.OK, billsStat); } catch (Exception ex) { ErrorObject err = new ErrorObject(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, err)); } return(response); }
public HttpResponseMessage GetClientBillsStat(int id, JObject jsonData) { HttpResponseMessage response; string s = jsonData.ToString().Replace(" ", ""); GetClientBillsStatCriterion criterion = jsonData.ToObject <GetClientBillsStatCriterion>(); criterion.ClientId = id; if (criterion.StartDateTime == null) { criterion.StartDateTime = ""; } else { criterion.StartDateTime = s.Substring(s.IndexOf("StartDateTime") + "StartDateTime".Length + 3, 19); } if (criterion.EndDateTime == null) { criterion.EndDateTime = ""; } else { criterion.EndDateTime = s.Substring(s.IndexOf("EndDateTime") + "EndDateTime".Length + 3, 19); } try { BillsStat clientBillsStat = queryBuilder .For <BillsStat>() .With(criterion); response = Request.CreateResponse(HttpStatusCode.OK, clientBillsStat); } catch (Exception ex) { ErrorObject err = new ErrorObject(ex.Message); return(Request.CreateResponse(HttpStatusCode.InternalServerError, err)); } return(response); }
public BillsStat GetClientBillsStat(int id, string startDateTime, string endDateTime) { if (!_clientService.VerifyId(id)) { throw new ArgumentException("No client with this id"); } if (!VerifyDateTime(startDateTime)) { throw new ArgumentException("Incorrect start datetime"); } if (!VerifyDateTime(endDateTime)) { throw new ArgumentException("Incorrect end datetime"); } if (startDateTime.CompareTo(endDateTime) > 0 && startDateTime != "" && endDateTime != "") { throw new ArgumentException("Start datetime after end datetime!"); } List <Bill> bills = new List <Bill>(); if (startDateTime != "" && endDateTime != "") { bills = _billRepository .All() .Where( bill => bill .CreatedAt .ToString("s") .CompareTo(startDateTime) >= 0 && bill .CreatedAt .ToString("s") .CompareTo(endDateTime) <= 0 && bill.ClientId == id ) .ToList(); } else if (startDateTime == "" && endDateTime != "") { bills = _billRepository .All() .Where( bill => bill .CreatedAt .ToString("s") .CompareTo(endDateTime) <= 0 && bill.ClientId == id ) .ToList(); } else if (startDateTime != "" && endDateTime == "") { bills = _billRepository .All() .Where( bill => bill .CreatedAt .ToString("s") .CompareTo(startDateTime) >= 0 && bill.ClientId == id ) .ToList(); } else { bills = _billRepository .All() .Where( bill => bill.ClientId == id ) .ToList(); } BillsStat clientBillsStat = new BillsStat(); clientBillsStat.TotalCount = bills.Count; clientBillsStat.PayedCount = bills.Count(bill => bill.WasPayed); clientBillsStat.UnpayedCount = clientBillsStat.TotalCount - clientBillsStat.PayedCount; clientBillsStat.TotalSum = bills.Sum(bill => bill.Sum); clientBillsStat.PayedSum = bills.Where(bill => bill.WasPayed).Sum(bill => bill.Sum); clientBillsStat.UnpayedSum = clientBillsStat.TotalSum - clientBillsStat.PayedSum; return(clientBillsStat); }