public RefillOrder AddRefillStatus(Subscription subscription) { Random random = new Random(); RefillOrder refillOrder = new RefillOrder() { RefillOrderId = random.Next(9, 50), SubscriptionId = subscription.SubscriptionId, DrugId = subscription.DrugId, DrugName = subscription.DrugName, Quantity = random.Next(3, 10), Payment = "Pending", RefillDate = DateTime.Today, PolicyId = random.Next(10, 1000), MemberId = subscription.MemberId }; if (subscription.RefillOccurrence == "Monthly") { refillOrder.NextRefillDate = refillOrder.RefillDate.AddMonths(1); } else { refillOrder.NextRefillDate = refillOrder.RefillDate.AddDays(7); } if (refillOrder == null) { return(null); } RefillHelper.refill.Add(refillOrder); return(refillOrder); }
//Checks Amount Status and Unsubscribes if NO Dues public Subscription RemoveSubscription(int drugId) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", SubscriptionHelper.SessionToken); var subscription = SubscriptionHelper.SubscriptionDetails.SingleOrDefault(s => s.DrugId == drugId); if (subscription == null) { return(null); } client.BaseAddress = new Uri("http://20.40.245.9/api/"); var responseTask = client.GetAsync("Refill/GetRefillStatus/" + subscription.SubscriptionId); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { string data = result.Content.ReadAsStringAsync().Result; RefillOrder refill = JsonConvert.DeserializeObject <RefillOrder>(data); RefillOrder status = new RefillOrder(); string subStatus = status.Payment; if (refill.Payment.Equals("Clear")) { SubscriptionHelper.SubscriptionDetails.Remove(subscription); return(subscription); } } return(null); } }
//Check for the frequency public List <RefillOrder> Occurrence(int subscriptionId, string frequency, DateTime date) { List <RefillOrder> details = new List <RefillOrder>(); if (string.Equals(frequency, "Monthly")) { RefillOrder refills = new RefillOrder(); var refill = RefillHelper.refill.SingleOrDefault(s => s.SubscriptionId == subscriptionId); refills.RefillOrderId = refill.RefillOrderId; refills.DrugId = refill.DrugId; refills.DrugName = refill.DrugName; refills.Quantity = refill.Quantity; refills.Payment = refill.Payment; refills.PolicyId = refill.PolicyId; refills.MemberId = refill.MemberId; refills.SubscriptionId = subscriptionId; date = date.AddMonths(1); refills.RefillDate = date; refills.NextRefillDate = date.AddMonths(1); details.Add(refills); } else if (string.Equals(frequency, "Weekly")) { RefillOrder refills = new RefillOrder(); var refill = RefillHelper.refill.SingleOrDefault(s => s.SubscriptionId == subscriptionId); refills.RefillOrderId = refill.RefillOrderId; refills.DrugId = refill.DrugId; refills.DrugName = refill.DrugName; refills.Quantity = refill.Quantity; refills.Payment = refill.Payment; refills.PolicyId = refill.PolicyId; refills.MemberId = refill.MemberId; refills.SubscriptionId = subscriptionId; date = date.AddDays(7); refills.RefillDate = date; refills.NextRefillDate = date.AddDays(7); details.Add(refills); } else { RefillOrder refills = new RefillOrder(); var refill = RefillHelper.refill.SingleOrDefault(s => s.SubscriptionId == subscriptionId); refills.RefillOrderId = refill.RefillOrderId; refills.DrugId = refill.DrugId; refills.DrugName = refill.DrugName; refills.Quantity = refill.Quantity; refills.Payment = refill.Payment; refills.PolicyId = refill.PolicyId; refills.MemberId = refill.MemberId; refills.SubscriptionId = subscriptionId; date = date.AddYears(1); refills.RefillDate = date; refills.NextRefillDate = date.AddYears(1); details.Add(refills); } return(details); }
public void RepositoryGetStatusTest1() { RefillOrder refillOrder = new RefillOrder(); Mock <IRefillOrderRepository> refillContextMock = new Mock <IRefillOrderRepository>(); var refillRepoObject = new RefillOrderRepository(); refillContextMock.Setup(x => x.RefillStatus(1)).Returns(refillOrder); var refillStatus = refillRepoObject.RefillStatus(1); Assert.IsNotNull(refillStatus); //Assert.AreEqual("Pending", refillStatus); }
// public RefillOrder RefillStatus(int SubscriptionId) public RefillOrder AdhocRefill(int PolicyId, int MemberID, int SubscriptionId, string auth) { // drugId and Location is taken from subscription service with the help of MemberId try { int DrugId = 1; string Location = "Delhi"; RefillOrder result = new RefillOrder(); using (var httpClient = new HttpClient()) { string[] token = auth.Split(" "); var content = new StringContent(JsonConvert.SerializeObject("hello"), Encoding.UTF8, "application/json"); var request = new HttpRequestMessage(HttpMethod.Post, "http://52.190.30.199/api/DrugsApi/getDispatchableDrugStock/" + DrugId + "/" + Location) { Content = content }; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token[1]); using (var response = httpClient.SendAsync(request).Result) { if (!response.IsSuccessStatusCode) { return(null); } var data = response.Content.ReadAsStringAsync().Result; var check = JsonConvert.DeserializeObject <bool>(data); if (check) { result.Id = refill[refill.Count - 1].Id + 1; result.RefillDate = DateTime.Now; result.DrugQuantity = 10; result.RefillDelivered = false; result.Payment = false; result.SubscriptionId = SubscriptionId; } refill.Add(result); return(result); } } } catch (Exception e) { return(null); } }
public ActionResult AdhocDrug_Refill(RefillOrder ad) { string Token = HttpContext.Request.Cookies["Token"]; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); string data = JsonConvert.SerializeObject(ad); StringContent content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync(client.BaseAddress + "/Refill/requestAdhocRefill/", content).Result; if (response.IsSuccessStatusCode) { string scheduleData = response.Content.ReadAsStringAsync().Result; Refill r = JsonConvert.DeserializeObject <Refill>(scheduleData); return(View("AdhocRefill", r)); } return(View()); }
public bool RequestAdhocRefill(int subscriptionId, int refillId) { try { RefillOrder refillOrder = (from RefillOrder order in _dbHelper.RefillOrders where order.SubscriptionID == subscriptionId && order.RefillOrderID == refillId select order).FirstOrDefault(); if (refillOrder != null) { refillOrder.Status = RefilStatus.Completed; return(true); } else { return(false); } } catch { return(false); } }
// public RefillOrder RefillStatus(int SubscriptionId) public RefillOrder AdhocRefill(int PolicyId, int MemberId, int SubscriptionId) { // drugId and Location is taken from subscription service with the help of MemberId int DrugId = 1; string Location = "Delhi"; RefillOrder result = new RefillOrder(); using (var httpClient = new HttpClient()) { var content = new StringContent(JsonConvert.SerializeObject("hello"), Encoding.UTF8, "application/json"); using (var response = httpClient.PostAsync("https://localhost:44393/api/DrugsApi/getDispatchableDrugStock/" + DrugId + "/" + Location, content).Result) { if (!response.IsSuccessStatusCode) { return(null); } var data = response.Content.ReadAsStringAsync().Result; var check = JsonConvert.DeserializeObject <bool>(data); if (check) { result.Id = 9; result.RefillDate = DateTime.Now; result.DrugQuantity = 10; result.RefillDelivered = false; result.Payment = false; result.SubscriptionId = SubscriptionId; } return(result); } } }
public bool CreateRefillOrders(RefillOrderDTO refillOrder) { List <RefillOrder> refills = new List <RefillOrder>(); try { if (refillOrder.RefillOccurrence == Occurrence.Weekly) { int days = 0; for (int i = 1; i <= refillOrder.CourseInWeeks; i++) { RefillOrder refill = new RefillOrder(); refill.RefillOrderID = refillNumber; refill.RefillDate = refillOrder.RefillDate.AddDays(days); refill.SubscriptionID = refillOrder.SubscriptionId; refill.Quantity = refillOrder.DosagePerDay * 7; refill.Location = refillOrder.Location; refill.Price = (refillOrder.DosagePerDay * 7) * refillOrder.CostPerUnit; refill.Status = RefilStatus.Pending; refillNumber++; days += 7; refills.Add(refill); } _dbHelper.RefillOrders.AddRange(refills); } else if (refillOrder.RefillOccurrence == Occurrence.Monthly) { if (refillOrder.CourseInWeeks % 4 == 0) { int rep = (refillOrder.CourseInWeeks / 4); int days = 0; for (int i = 1; i <= rep; i++) { RefillOrder refill = new RefillOrder(); refill.RefillOrderID = refillNumber; refill.RefillDate = refillOrder.RefillDate.AddDays(days); refill.SubscriptionID = refillOrder.SubscriptionId; refill.Quantity = refillOrder.DosagePerDay * 28; refill.Location = refillOrder.Location; refill.Price = (refillOrder.DosagePerDay * 28) * refillOrder.CostPerUnit; refill.Status = RefilStatus.Pending; refillNumber++; days += 28; refills.Add(refill); } } else { int rep = (refillOrder.CourseInWeeks / 4); int days = 0; for (int i = 1; i <= rep; i++) { RefillOrder refill = new RefillOrder(); refill.RefillOrderID = refillNumber; refill.RefillDate = refillOrder.RefillDate.AddDays(days); refill.SubscriptionID = refillOrder.SubscriptionId; refill.Quantity = refillOrder.DosagePerDay * 28; refill.Location = refillOrder.Location; refill.Price = (refillOrder.DosagePerDay * 28) * refillOrder.CostPerUnit; refill.Status = RefilStatus.Pending; refillNumber++; days += 28; refills.Add(refill); } int remWeekly = refillOrder.CourseInWeeks - (rep * 4); for (int i = 1; i <= remWeekly; i++) { RefillOrder refill1 = new RefillOrder(); refill1.RefillOrderID = refillNumber; refill1.RefillDate = refillOrder.RefillDate.AddDays(days); refill1.SubscriptionID = refillOrder.SubscriptionId; refill1.Quantity = refillOrder.DosagePerDay * 7; refill1.Location = refillOrder.Location; refill1.Price = (refillOrder.DosagePerDay * 7) * refillOrder.CostPerUnit; refill1.Status = RefilStatus.Pending; refillNumber++; days += 7; refills.Add(refill1); } _dbHelper.RefillOrders.AddRange(refills); } } return(true); } catch (Exception) { return(false); } }