public CycleViewModel GetViewModel(Cycle cycle, IDictionary <object, object> map = null) { if (cycle == null) { return(null); } // If called without map - create new one if (map == null) { map = new Dictionary <object, object>(); } // if we already mapped this cycle before - don't do this again // and instead return already mapped entity if (map.ContainsKey(cycle)) { return((CycleViewModel)map[cycle]); } var viewModel = new CycleViewModel(); viewModel.PatientId = cycle.PatientId; viewModel.CycleId = cycle.CycleId; viewModel.IsActive = cycle.IsActive; // add this entity to map before calling any other mappers map.Add(cycle, viewModel); // pass map to other mapper viewModel.Patient = PatientMapper.GetViewModel(cycle.Patient, map); return(viewModel); }
public ActionResult Create(CycleViewModel cycle) { if (ModelState.IsValid) { Cycle cycleToAdd = new Cycle { CycleStatusType = cycle.CycleStatusType, CompanyId = cycle.CompanyId, CycleType = cycle.CycleType, StoreId = cycle.StoreId, CostPerHour = cycle.CostPerHour }; _unitOfWork.Cycles.Add(cycleToAdd); var store = _unitOfWork.Stores.Get(cycle.StoreId); store.TotalCycle += 1; _unitOfWork.Complete(); return(RedirectToAction("Index")); } CycleViewModel model = new CycleViewModel { CompanyList = new SelectList(_unitOfWork.Companies.GetAll(), "CompanyId", "Name"), StoreList = new SelectList(_unitOfWork.Stores.GetAll(), "StoreId", "Name") }; return(View(model)); }
public ActionResult Edit(int id, CycleViewModel model) { try { // TODO: Add update logic here if (ModelState.IsValid) { Cycle cycleToUpdate = _unitOfWork.Cycles.Get(id); cycleToUpdate.CompanyId = model.CompanyId; cycleToUpdate.StoreId = model.StoreId; cycleToUpdate.CycleStatusType = model.CycleStatusType; cycleToUpdate.CycleType = model.CycleType; cycleToUpdate.CostPerHour = model.CostPerHour; _unitOfWork.Complete(); return(RedirectToAction("Index")); } return(View()); } catch { return(View()); } }
public ActionResult EditCycle(CycleViewModel viewModel) { if (!CurrentUser.IsAdmin) { throw new Exception("Unauthorized user access"); } new CycleService().UpdateCycle(viewModel.CycleId, viewModel.StartDate, viewModel.EndDate); return(RedirectToAction("Cycles")); }
// GET: Cycle/Create public ActionResult Create() { CycleViewModel model = new CycleViewModel { CompanyList = new SelectList(_unitOfWork.Companies.GetAll(), "CompanyId", "Name"), StoreList = new SelectList(_unitOfWork.Stores.GetAll(), "StoreId", "Name") }; return(View(model)); }
public ActionResult EditCycleView(long?cycleId) { var cycle = new CycleService().RetrieveCycleById(cycleId.Value); if (cycle == null) { throw new Exception("Cycle was not found"); } var viewModel = new CycleViewModel { CycleId = cycle.CycleId, StartDate = cycle.StartDate, EndDate = cycle.EndDate }; return(PartialView("~/Views/Admin/_EditCycle.cshtml", viewModel)); }
public ActionResult Edit(int id) { var cycle = _unitOfWork.Cycles.Get(id); CycleViewModel viewModel = new CycleViewModel { CycleId = cycle.CycleId, CompanyId = cycle.CompanyId, CycleType = cycle.CycleType, StoreId = cycle.StoreId, CycleStatusType = cycle.CycleStatusType, CompanyList = new SelectList(_unitOfWork.Companies.GetAll(), "CompanyId", "Name"), StoreList = new SelectList(_unitOfWork.Stores.GetAll(), "StoreId", "Name"), CostPerHour = cycle.CostPerHour }; return(View(viewModel)); }
/// <summary> /// Adds an cycle to the cycle notifications collection, and then removes the cycle 10 seconds later /// </summary> private void DisplayCycleNotification(CycleViewModel cycleData) { const int SLEEP_TIME = 250; if (this.UserData.AreCycleNotificationsEnabled) { if (!this.CycleNotifications.Contains(cycleData)) { Task.Factory.StartNew(() => { logger.Info("Displaying notification for \"{0}\"", cycleData.CycleName); Threading.BeginInvokeOnUI(() => this.CycleNotifications.Add(cycleData)); if (this.UserData.NotificationDuration > 0) { // For X seconds, loop and sleep, with checks to see if notifications have been disabled for (int i = 0; i < (this.UserData.NotificationDuration * 1000 / SLEEP_TIME); i++) { System.Threading.Thread.Sleep(SLEEP_TIME); if (!this.UserData.AreCycleNotificationsEnabled) { logger.Debug("Removing notification for \"{0}\"", cycleData.CycleName); Threading.BeginInvokeOnUI(() => this.CycleNotifications.Remove(cycleData)); } } logger.Debug("Removing notification for \"{0}\"", cycleData.CycleName); // TODO: I hate having this here, but due to a limitation in WPF, there's no reasonable way around this at this time // This makes it so that the notifications can fade out before they are removed from the notification window Threading.BeginInvokeOnUI(() => cycleData.IsRemovingNotification = true); System.Threading.Thread.Sleep(SLEEP_TIME); Threading.BeginInvokeOnUI(() => { this.CycleNotifications.Remove(cycleData); cycleData.IsRemovingNotification = false; }); } }); } } }