public IPractice CastToDbModel(PracticeViewModel practiceVm) { var practiceDb = new Practice { Id = practiceVm.Id, ConcurrencyStamp = practiceVm.ConcurrencyStamp, Description = practiceVm.Description, MaxParticipants = practiceVm.MaxParticipants }; DateTime baseDate = new DateTime(); if (!string.IsNullOrEmpty(practiceVm.PracticeDate)) { bool res = DateTime.TryParse(practiceVm.PracticeDate, out baseDate); if (!res) { throw new Exception("Cannot parse practice date in practice service."); } } if (!string.IsNullOrEmpty(practiceVm.Begins)) { try { TimeSpan beginTime = Convert.ToDateTime(practiceVm.Begins).TimeOfDay; var beginning = baseDate; beginning += beginTime; practiceDb.Begins = beginning; } catch (Exception ex) { throw new Exception($"Cannot parse begins time in practice service. {ex.Message}"); } } if (!string.IsNullOrEmpty(practiceVm.Ends)) { try { TimeSpan endTime = Convert.ToDateTime(practiceVm.Ends).TimeOfDay; var ending = baseDate; ending += endTime; practiceDb.Ends = ending; } catch (Exception ex) { throw new Exception($"Cannot parse end time in practice service. {ex.Message}"); } } return(practiceDb); }
public IActionResult Edit(PracticeViewModel practice) { if (ModelState.IsValid) { var res = _practiceService.Update(practice); if (res) { return(RedirectToAction("Index")); } return(RedirectToAction("Index", new { Message = RolesMessageId.ConcurrecyError })); } return(View()); }
public ActionResult Edit(PracticeViewModel model) { if (!ModelState.IsValid) { return(View(model)); } model.Practice.State = model.Practice.State?.ToUpper(); _practiceRepository.Save(model); return(RedirectToAction("View", new { id = model.Practice.Id })); }
public ActionResult Edit(int id, PracticeViewModel practiceViewModel) { if (ModelState.IsValid) { var practiceModel = AutoMapper.Mapper.Map <PracticeViewModel, Practice>(practiceViewModel); this.practiceService.Update(practiceModel); return(RedirectToAction("Index", new { perspectiveId = practiceViewModel.PerspectiveId })); } return(View(practiceViewModel)); }
public static PracticeViewModel CreateWordPracticeViewModel() { var practiceViewModel = new PracticeViewModel { Name = "Контрольная работа №1. Microsoft Word", Description = "В данной контрольной работе вам необходимо выполнить форматирование текста по правилам в документе Microsoft Word. \n Перейдите в приложение для практических заданий и выполните задание", IsVisible = true, CurrentTheoryId = -1, PracticeType = PracticeType.Word }; AddWordOptions(practiceViewModel); return(practiceViewModel); }
public static PracticeViewModel CreateExcelPracticeViewModel() { var practiceViewModel = new PracticeViewModel { Name = "Контрольная работа №2. Microsoft Excel", Description = "В данной контрольной работе вам необходимо выполнить расчет по формулам в Microsoft Office Excel. \n Перейдите в приложение для практических заданий и выполните задание", IsVisible = true, CurrentTheoryId = -2, PracticeType = PracticeType.Excel }; AddExcelOptions(practiceViewModel); return(practiceViewModel); }
public ActionResult EditContact(DoctorContactViewModel viewModel) { if (!ModelState.IsValid) { InitViewBag(); return(View(viewModel)); } //var returnMsg = "There was an error updating this Doctor's information."; if (viewModel.Status != viewModel.OriginalStatus || viewModel.StatusDate == DateTime.MinValue) { viewModel.StatusDate = DateTime.Now; } if (viewModel.Id == 0) { viewModel.DateEntered = DateTime.Now; viewModel.EnteredBy = Session["UserId"].ToString(); viewModel.DateLastUpdated = viewModel.DateEntered; viewModel.LastUpdatedBy = viewModel.EnteredBy; } else { viewModel.DateLastUpdated = DateTime.Now; viewModel.LastUpdatedBy = Session["UserId"].ToString(); } // See if user added a new Practice on the fly if (viewModel.PracticeId == -1 && !string.IsNullOrEmpty(viewModel.Practice.PracticeName)) { var practice = new PracticeViewModel() { Practice = viewModel.Practice }; practice.Practice.Id = 0; // signal we are Inserting _practiceRepository.Save(practice); viewModel.PracticeId = practice.Practice.Id; } _doctorRepository.SaveContact(viewModel); //if (_doctorRepository.Save(model)) // returnMsg = $"Contact information for {model.FirstName + " " + model.LastName} was edited successfully."; return(RedirectToAction("View", new { id = viewModel.Id })); }
public IActionResult Create(PracticeViewModel practice) { if (ModelState.IsValid) { practice.Id = Guid.NewGuid(); practice.ConcurrencyStamp = Guid.NewGuid().ToString(); var res = _practiceService.Create(practice); if (res) { return(RedirectToAction("Index")); } return(View()); } return(View(practice)); }
public bool Create(IGeekyObj geekyObject) { PracticeViewModel practiceVm = geekyObject as PracticeViewModel; if (practiceVm == null) { return(false); } var practiceDb = CastToDbModel(practiceVm) as Practice; _swimteamDb.Practices.Add(practiceDb); var recordCount = _swimteamDb.SaveChanges(); return(recordCount > 0); }
public async Task <IActionResult> Practice(int howMany, PracticeOrLearn practiceOrLearn, string groupId = null) { var model = new PracticeViewModel(); var user = await _userManager.GetUserAsync(User); if (howMany == 0 || practiceOrLearn == PracticeOrLearn.Undefined) { RedirectToAction("BeforePractice"); } if (practiceOrLearn == PracticeOrLearn.Learn && groupId == null) { foreach (var item in _loadFlashcardsForLearnWhereUserId.Load(user.Id, howMany)) { model.FlashcardPracticeModels.Add(item.ConvertToFlashcardPracticeModel()); } } if (practiceOrLearn == PracticeOrLearn.Practice && groupId == null) { foreach (var item in _loadFlashcardsForPracticeWhereUserId.Load(user.Id, howMany)) { model.FlashcardPracticeModels.Add(item.ConvertToFlashcardPracticeModel()); } } if (practiceOrLearn == PracticeOrLearn.Learn && groupId != null) { foreach (var item in _loadFlashcardsForLearnWhereGroupId.Load(Guid.Parse(groupId), howMany)) { model.FlashcardPracticeModels.Add(item.ConvertToFlashcardPracticeModel()); } } if (practiceOrLearn == PracticeOrLearn.Practice && groupId != null) { foreach (var item in _loadFlashcardsForPracticeWhereGroupId.Load(Guid.Parse(groupId), howMany)) { model.FlashcardPracticeModels.Add(item.ConvertToFlashcardPracticeModel()); } } return(View(model)); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (container is FrameworkElement element && item is PracticeViewModel) { PracticeViewModel practiceViewModel = (PracticeViewModel)item; if (practiceViewModel.PracticeType == PracticeType.Excel) { return(element.FindResource("ExcelPracticeView") as DataTemplate); } if (practiceViewModel.PracticeType == PracticeType.Word) { return(element.FindResource("WordPracticeView") as DataTemplate); } } return(base.SelectTemplate(item, container)); }
// GET: Practices/Create public async Task <IActionResult> CreateAsync() { var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Challenge()); } PracticeViewModel pvm = new PracticeViewModel() { AvailableDogs = _db.Dogs.Where(d => d.ApplicationUserId == currentUser.Id) .ToDictionary(x => x.Id, x => $"{ x.Id }({ x.DogName })"), AvailableSkills = _db.Skills.ToDictionary(s => s.Id, s => $"{ s.Id }({ s.Name })"), Practice = new Practice() }; return(View(pvm)); }
/// <summary> /// Get Practice details and a list of all Doctors at the Practice /// </summary> /// <param name="id"></param> /// <returns></returns> internal PracticeViewModel Get(int id) { var model = new PracticeViewModel(); using (var conn = Connection) { var sql = $"select * from hlc_Practice where ID={id};" + "select d.id, d.FirstName, d.LastName, d.MobilePhone, d.Attitude, p.PracticeName, p.OfficePhone1 " + "from hlc_Doctor d " + "left join hlc_Practice p on p.ID = d.PracticeID " + $"where d.PracticeId = {id} " + "order by d.LastName, d.FirstName;"; conn.Open(); var multi = conn.QueryMultiple(sql); model.Practice = multi.Read <Practice>().FirstOrDefault(); model.Doctors = multi.Read <Doctor>().ToList(); } return(model); }
public ActionResult Edit(int id) { // Use PracticeViewModel and reference .Practice portion because the .Get() returns this model var model = new PracticeViewModel(); if (id == 0) { model.Practice = new Practice(); model.Practice.FacilityType = FacilityType.Practice; } else { model = _practiceRepository.Get(id); if (model == null) { return(RedirectToAction("Search", "Home", new { msg = $"Hospital {id} was not found in the database." })); } } return(View(model)); }
internal bool Save(PracticeViewModel model) { try { if (model.Practice.Id == 0) { Connection.Insert(model.Practice); } else { Connection.Update(model.Practice); } GetSelectList(FacilityType.Practice, true); GetSelectList(FacilityType.Legal, true); return(true); } catch (Exception ex) { LogException(ex, model.Practice); return(false); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (NavigationContext.QueryString.ContainsKey("resume") || (isNewInstance && e.NavigationMode != NavigationMode.New)) { try { using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var file = storage.OpenFile("Session", FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var sr = new StreamReader(file)) { var json = JsonValue.Parse(sr); session = new JsonContext().FromJson <PracticeViewModel>(json); } } } } catch (IsolatedStorageException) { } catch (IOException) { } catch (FormatException) {} return; } base.OnNavigatedTo(e); }
void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { if (!isNewInstance) { return; } isNewInstance = false; if (NavigationContext.QueryString.ContainsKey("resume")) { DataContext = session; gamePanel.Visibility = Visibility.Visible; return; } if (State.ContainsKey("Session")) { DataContext = session = RestoreJsonState <PracticeViewModel>("Session"); gamePanel.Visibility = Visibility.Visible; return; } // TODO: Doesn't download terms from API if not cached var sets = ((from setID in this.GetIDListParameter <long>("sets", required: false) select App.ViewModel.GetSet(setID, true)) .Concat(from g in this.GetIDListParameter <long>("groups", required: false).Select(App.ViewModel.GetGroup) where g != null from set in g.Sets select set)).ToArray(); foreach (var set in sets) { set.LoadTerms(); } TryDownloadTerms(sets); }
public PracticeViewModel CastToViewModel(IPractice practiceD) { Practice domainPractice = practiceD as Practice; if (domainPractice == null) { return(new PracticeViewModel()); } var practiceVm = new PracticeViewModel { Id = domainPractice.Id, ConcurrencyStamp = domainPractice.ConcurrencyStamp, Description = domainPractice.Description, MaxParticipants = domainPractice.MaxParticipants }; practiceVm.PracticeDate = domainPractice.Begins.ToString("d"); practiceVm.Begins = domainPractice.Begins.ToString("t"); practiceVm.Ends = domainPractice.Ends.ToString("t"); return(practiceVm); }
public async Task <IActionResult> Create(PracticeViewModel pvm, Practice practice) { var userId = _userManager.GetUserId(User); var user = await _userManager.FindByIdAsync(userId); var currentUser = await _userManager.GetUserAsync(User); practice.ApplicationUserId = currentUser.Id; practice.Date = pvm.Date; practice.Rounds = pvm.Rounds; practice.Score = pvm.Score; practice.Notes = pvm.Notes; practice.DogId = pvm.DogId; practice.SkillId = pvm.SkillId; pvm.AvailableDogs = _db.Dogs.Where(d => d.ApplicationUserId == currentUser.Id) .ToDictionary(x => x.Id, x => $"{ x.Id }({ x.DogName })"); pvm.AvailableSkills = _db.Skills.ToDictionary(s => s.Id, s => $"{ s.Id }({ s.Name })"); _db.Add(practice); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public IActionResult Practice(PracticeViewModel inputModel) { _reCalculateAndUpdatePracticePropertiesList.ReCauculate(inputModel.FlashcardPracticeModels); return(RedirectToAction("Index", "Manage")); }
void EndSession(object sender, EventArgs e) { session = null; NavigationService.GoBack(); }