private async Task <IActionResult> BuildCreateOrEditDisplayAsync(CreateOrEditDailyStatisticViewModel model) { if (model == null) { model = new CreateOrEditDailyStatisticViewModel(); } var jobs = await _jobQuerier.GetJobsAsync(); if (jobs != null) { model.Jobs = jobs.Select(s => new SelectListItem() { Value = s.Id.ToString(), Text = s.Title }).ToList(); } var dictionaries = await _dictionaryQuerier.GetDictionaryAsync(ResumeDefaults.PlatformType); if (dictionaries != null) { model.Platforms = dictionaries.Select(s => new SelectListItem() { Text = s.Name, Value = s.Name }).ToList(); } return(View(model)); }
public async Task <IActionResult> Create(CreateOrEditDailyStatisticViewModel model) { if (ModelState.IsValid) { var dailyStatistic = Mapper.Map <DailyStatistic>(model); await _dailyStatisticManager.CreateAsync(dailyStatistic); Notifier.Success($"你已成功创建了“{model.Date}”的统计记录!"); return(RedirectToAction(nameof(List))); } return(await BuildCreateOrEditDisplayAsync(model)); }
public async Task <IActionResult> Edit(CreateOrEditDailyStatisticViewModel model) { if (ModelState.IsValid) { var dailyStatistic = await _dailyStatisticManager.FindByIdAsync(model.Id.Value); if (dailyStatistic == null) { return(NotFound(model.Id.Value)); } _ = Mapper.Map(model, dailyStatistic); await _dailyStatisticManager.UpdateAsync(dailyStatistic); Notifier.Success($"你已成功编辑了“{model.Date}”的统计记录!"); return(RedirectToAction(nameof(List))); } return(await BuildCreateOrEditDisplayAsync(model)); }