public async Task <List <GetSettlementResponse> > getSettlements() { var settlements = new List <GetSettlementResponse>(); var sett = _Context.settlements.ToList(); for (int i = 0; i < sett.Count; i++) { GetSettlementResponse getSettlement = new GetSettlementResponse(); if (sett[i].groupId != null) { var nameid2 = _Context.groups.SingleOrDefault(c => c.groupid == sett[i].groupId); var detail2 = new Detail(); detail2.id = nameid2.groupid; detail2.name = nameid2.group_name; getSettlement.group = detail2; } var detail1 = new Detail(); var nameid1 = _Context.users.SingleOrDefault(c => c.userid == sett[i].payerId); detail1.name = nameid1.user_name; detail1.id = nameid1.userid; getSettlement.payer = detail1; var detail = new Detail(); var nameid = _Context.users.SingleOrDefault(c => c.userid == sett[i].payeeId); detail.name = nameid.user_name; detail.id = nameid.userid; getSettlement.payee = detail; getSettlement.amount = sett[i].amount; settlements.Add(getSettlement); } return(settlements); }
public IHttpActionResult GetById(int id) { GetSettlementResponse response = new GetSettlementResponse(); try { List <Settlement> settlement = settlementBL.GetSettlement(id); response.Settlements = settlement; response.Success = true; } catch (SettlementException ex) { response.ErrorCode = ex.Error; response.ErrorMessage = "Error. " + ex.Error.ToString(); response.Success = false; } catch (Exception ex) { response.ErrorMessage = "Error. " + ex.Message; response.Success = false; } return(Ok(response)); }
public void TestInsertUpdateGetAndDeleteSettlement() { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); SettlementResponse settlementResponse = new SettlementResponse(); //Test insert Settlement settlement = new Settlement(); settlement.CicleId = 1; //Assume we have a cicle with ID 1 settlement.ProducerId = 1; //Assume we have a producer with ID 1 settlement.CashAdvancesTotal = 1000; settlement.Date = DateTime.Now; settlement.CreditsTotal = 2000; settlement.Paid = false; settlement.WeightTicketsTotal = 2500; settlement.Total = 5000; settlement.User = "******"; //Assume we have a user with this ID settlement.WeightTicketsIds = new System.Collections.ObjectModel.Collection <int>() { 1 }; string jsonSettlement = javaScriptSerializer.Serialize(settlement); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); HttpResponseMessage response = client.PostAsJsonAsync(insertAction, settlement).Result; Assert.IsTrue(response.IsSuccessStatusCode); settlementResponse = response.Content.ReadAsAsync <SettlementResponse>().Result; Assert.IsTrue(settlementResponse.Success); //Test update settlement = settlementResponse.Settlement; settlement.Paid = true; response = client.PostAsJsonAsync(updateAction, settlement).Result; Assert.IsTrue(response.IsSuccessStatusCode); settlementResponse = response.Content.ReadAsAsync <SettlementResponse>().Result; Assert.IsTrue(settlementResponse.Success); //TODO VERIFY TICKETS CHANGED PAID STATUS //Test get all GetSettlementResponse getSettlementResponse = new GetSettlementResponse(); response = client.GetAsync(getAllAction).Result; Assert.IsTrue(response.IsSuccessStatusCode); getSettlementResponse = response.Content.ReadAsAsync <GetSettlementResponse>().Result; Assert.IsTrue(getSettlementResponse.Success); Assert.IsTrue(getSettlementResponse.Settlements.Count > 0); //Test get by Id string getByIdUrl = string.Format("{0}?id={1}", getByIdAction, settlement.Id.ToString()); response = client.GetAsync(getByIdUrl).Result; Assert.IsTrue(response.IsSuccessStatusCode); getSettlementResponse = response.Content.ReadAsAsync <GetSettlementResponse>().Result; Assert.IsTrue(getSettlementResponse.Success); Assert.IsTrue(getSettlementResponse.Settlements.Count > 0); //Test delete response = client.PostAsJsonAsync(deleteAction, new IdModel(settlementResponse.Settlement.Id)).Result; Assert.IsTrue(response.IsSuccessStatusCode); settlementResponse = response.Content.ReadAsAsync <SettlementResponse>().Result; Assert.IsTrue(response.IsSuccessStatusCode); }