public void StartScheduleTestListMethod() { DataContext dataContext = new DataContext(); PacketDetailRepository packetDetailRepository = new PacketDetailRepository(dataContext); PacketTypeRepository packetTypeRepository = new PacketTypeRepository(dataContext); ErrorLogsRepository errorLogsRepository = new ErrorLogsRepository(dataContext); string startScheduleDate = Convert.ToString(TestContext.DataRow["StartDate"]); RationScheduleViewModelNew rationScheduleViewModelNew = new RationScheduleViewModelNew(); rationScheduleViewModelNew.statedate = startScheduleDate; RationController rationController = new RationController(packetDetailRepository, packetTypeRepository, errorLogsRepository); // Act ViewResult result = rationController.Schduled(rationScheduleViewModelNew) as ViewResult; // Assert if (result != null) { Assert.IsNotNull(result.Model); } else { Assert.IsNull(result); } }
private string AddDayInCurrentDate(string date, RationScheduleViewModelNew rationScheduleView) { string[] dateFormate = date.Split('-'); rationScheduleView.statedate = (Convert.ToInt32(dateFormate[0]) + 1).ToString() + "-" + dateFormate[1] + "-" + dateFormate[2].ToString(); var V = Convert.ToDateTime(dateFormate[2] + "-" + dateFormate[1] + "-" + (dateFormate[0].Length == 1 ? "0" : "" + (Convert.ToInt32(dateFormate[0])).ToString())).AddDays(1); return(V.ToString()); }
//GET: Method For open the Schduler page public ActionResult Schduled() { try { RationScheduleViewModelNew rationScheduleViewModel = new RationScheduleViewModelNew(); rationScheduleViewModel.StartDate = DateTime.Now; return(View(rationScheduleViewModel)); } catch (Exception ex) { LogException(ex, "Schduled"); RedirectToAction("Schduled", "Ration"); throw ex; } }
public void RationControllerPostSchudle() { //RationScheduleViewModel rationScheduleViewModel =new RationScheduleViewModel(); RationScheduleViewModelNew rationScheduleViewModel = new RationScheduleViewModelNew(); rationScheduleViewModel.StartDate = DateTime.Now; DataContext dataContext = new DataContext(); PacketDetailRepository packetDetailRepository = new PacketDetailRepository(dataContext); PacketTypeRepository packetTypeRepository = new PacketTypeRepository(dataContext); ErrorLogsRepository errorLogsRepository = new ErrorLogsRepository(dataContext); RationController rationController = new RationController(packetDetailRepository, packetTypeRepository, errorLogsRepository); ViewResult result = rationController.Schduled(rationScheduleViewModel) as ViewResult; // Assert if (result != null) { Assert.IsNotNull(result); } else { Assert.IsNull(result); } }
private void ParseDateTime(RationScheduleViewModelNew rationScheduleView) { string[] dtformat = rationScheduleView.statedate.Split('-'); rationScheduleView.StartDate = DateTime.Parse(dtformat[2] + "-" + dtformat[1] + "-" + (dtformat[0].Length == 1 ? "0" : "") + (Convert.ToInt32(dtformat[0])).ToString()); }
public ActionResult Schduled(RationScheduleViewModelNew rationScheduleView) { try { //DateTime StartDate List <RationScheduleViewModel> rationScheduleViewModels = new List <RationScheduleViewModel>(); ParseDateTime(rationScheduleView); int NumberInventery = 0; var Schduledata = _packetDetail.GetAll().Where(x => x.IsDeleted == false && (EntityFunctions.TruncateTime(x.ExpiryDate) >= EntityFunctions.TruncateTime(rationScheduleView.StartDate) || x.ExpiryDate == null)).OrderBy(a => a.LitersQty).OrderBy(a => a.Calories).ToList(); List <PacketDetail> PacketsLst = new List <PacketDetail>(); List <PacketDetail> paketDetailsItems = new List <PacketDetail>(); int Calories = 0; int QtyForLiter = 0; var Counter = 0; var CounterLtr = 0; var CounterCalories = 0; int CalRequire = 0; int LtrQty = 0; SchduleItem: //foreach (var item in Schduledata) int intCount = Schduledata.Count; for (int i = 0; i < intCount; i++) { var item = Schduledata.OrderBy(x => Convert.ToInt32(2500 - (x.Calories + Calories))).OrderBy(x => Math.Abs(Convert.ToInt32(2500 - (x.Calories + Calories)))) .OrderBy(x => Convert.ToInt32(2 - (x.LitersQty + QtyForLiter))).OrderBy(x => Math.Abs(Convert.ToInt32(2 - (x.LitersQty + QtyForLiter)))) .FirstOrDefault(); int PacketTypeId = Convert.ToInt32(item.PacketTypeId); PacketDetail packetDetail = new PacketDetail(); packetDetail.Id = item.Id; packetDetail.PacketTypeId = item.PacketTypeId; packetDetail.PacketType = _packetType.GetByID(PacketTypeId).PacketType; packetDetail.PacketContent = item.PacketContent != null ? item.PacketContent : "-"; packetDetail.Calories = item.Calories != null ? item.Calories : 0; packetDetail.ExpiryDate = item.ExpiryDate != null ? item.ExpiryDate : null; packetDetail.LitersQty = item.LitersQty != null ? item.LitersQty : 0; packetDetail.PacketId = item.PacketTypeId == "1" ? "F" + item.Id : "W" + item.Id; //This is for water packet type if (item.PacketTypeId == "2") { // List for store water actucal records if (QtyForLiter < 2) { PacketsLst.Add(packetDetail); Counter = Counter + 1; QtyForLiter += Convert.ToInt32(item.LitersQty); } // List for store water temp records else { PacketDetail packetDetailLtrTemp = new PacketDetail(); packetDetailLtrTemp.Id = item.Id; packetDetailLtrTemp.PacketTypeId = item.PacketTypeId; packetDetailLtrTemp.PacketType = _packetType.GetByID(PacketTypeId).PacketType; packetDetailLtrTemp.PacketContent = item.PacketContent != null ? item.PacketContent : "-"; packetDetailLtrTemp.Calories = item.Calories != null ? item.Calories : 0; packetDetailLtrTemp.ExpiryDate = item.ExpiryDate != null ? item.ExpiryDate : null; packetDetailLtrTemp.LitersQty = item.LitersQty != null ? item.LitersQty : 0; packetDetailLtrTemp.PacketId = item.PacketTypeId == "1" ? "F" + item.Id : "W" + item.Id; if (item.LitersQty != null) { CounterLtr = CounterLtr + 1; } paketDetailsItems.Add(packetDetailLtrTemp); } } //This is for food packet type else if (item.PacketTypeId == "1") { // List for store calories actucal records if (Calories < 2500) { PacketsLst.Add(packetDetail); Counter = Counter + 1; Calories += Convert.ToInt32(item.Calories); } // List for store calories temp records else { PacketDetail packetCalTempDetail = new PacketDetail(); packetCalTempDetail.Id = item.Id; packetCalTempDetail.PacketTypeId = item.PacketTypeId; packetCalTempDetail.PacketType = _packetType.GetByID(PacketTypeId).PacketType; packetCalTempDetail.PacketContent = item.PacketContent != null ? item.PacketContent : "-"; packetCalTempDetail.Calories = item.Calories != null ? item.Calories : 0; if (item.Calories != null) { CounterCalories = CounterCalories + 1; } packetCalTempDetail.ExpiryDate = item.ExpiryDate != null ? item.ExpiryDate : null; packetCalTempDetail.LitersQty = item.LitersQty != null ? item.LitersQty : 0; packetCalTempDetail.PacketId = item.PacketTypeId == "1" ? "F" + item.Id : "W" + item.Id; paketDetailsItems.Add(packetCalTempDetail); } } // Logic for display the row or cells based on the date if (Calories >= 2500 && QtyForLiter >= 2) { RationScheduleViewModel rationScheduleViewModel = new RationScheduleViewModel(); if (rationScheduleView.StartDate != null) { rationScheduleViewModel.StartDate = rationScheduleView.StartDate; } NumberInventery = NumberInventery + 1; rationScheduleViewModel.LivedLife = NumberInventery; rationScheduleViewModel.CounterSpan = Counter; foreach (var Packetitem in PacketsLst) { rationScheduleViewModel.listRation.Add(Packetitem); } rationScheduleViewModels.Add(rationScheduleViewModel); PacketsLst = new List <PacketDetail>(); Counter = 0; Calories = 0; QtyForLiter = 0; rationScheduleView.StartDate = rationScheduleView.StartDate.Date.AddDays(1); } Schduledata.Remove(item); } // this is for If actual list contain some records but not fullfill our logic condition if (PacketsLst.Count != 0) { Schduledata = PacketsLst; Calories = 0; QtyForLiter = 0; Counter = 0; PacketsLst = new List <PacketDetail>(); Schduledata.AddRange(paketDetailsItems); } else { Schduledata = paketDetailsItems; } Schduledata = Schduledata.OrderBy(a => a.LitersQty).OrderBy(a => a.Calories).ToList(); if (Schduledata.Count != 0) { foreach (var item in Schduledata) { if (item.Calories != 0) { CalRequire += Convert.ToInt32(item.Calories); } if (item.LitersQty != 0) { LtrQty += Convert.ToInt32(item.LitersQty); } } //If our tempCal & tempLtQty contain calories and qtyLr more than 2500 & 2 if (CalRequire >= 2500 && LtrQty >= 2) { CalRequire = 0; LtrQty = 0; paketDetailsItems = new List <PacketDetail>(); CounterLtr = 0; CounterCalories = 0; goto SchduleItem; } } RationScheduleViewModelNew rationScheduleViewModelNew = new RationScheduleViewModelNew(); rationScheduleViewModelNew.StartDate = rationScheduleView.StartDate; rationScheduleViewModelNew.lstRationScheduleViewModel = rationScheduleViewModels; return(View(rationScheduleViewModelNew)); } catch (Exception ex) { LogException(ex, "Schduled"); return(Json(null)); } }