public async Task<ActionResult> Create(int? personId, string taskDateTime) { if (personId == null) { return HttpNotFound(); } DateTime taskStart = _timeZoneHelper.ParseDateTime(taskDateTime); TimeSpan timeZoneOffset = GetCurrentTimeZoneOffset(); var taskDateStart = _timeZoneHelper.GetLocalDateTime(taskStart, timeZoneOffset).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); var taskTimeStart = _timeZoneHelper.GetLocalDateTime(taskStart, timeZoneOffset).ToShortTimeString(); var person = await Task.Run(() => _uow.PersonRepository.GetById(personId)); var task = new PersonTaskViewModel { StartTime = taskStart, StartDateValue = taskDateStart, StartTimeValue = taskTimeStart, PersonId = personId.Value, ProjectId = person.Project.Id, Hours = TimeSpan.FromHours(2) }; SetDataToViewBag(); return PartialView(task); }
public async Task<JsonResult> Create(PersonTaskViewModel personTaskViewModel) { try { if (ModelState.IsValid) { var person = await Task.Run(() => _uow.PersonRepository.GetById(personTaskViewModel.PersonId)); var personWorkMonth = await Task.Run(() => _uow.PersonWorkMonthRepository.GetPersonWorkMonth(person, DateTime.Today.Year, DateTime.Today.Month)); TimeSpan timeZoneOffset = GetCurrentTimeZoneOffset(); personTaskViewModel.StartTime = _timeZoneHelper.GetUtcDateTime(personTaskViewModel.StartDateValue, personTaskViewModel.StartTimeValue, timeZoneOffset); var personTask = _dataMapper.GetWrapper<CustomPersonTask, PersonTaskViewModel>(personTaskViewModel); personTask.Project = await Task.Run(() => _uow.ProjectRepository.GetById(personTaskViewModel.ProjectId)); personTask.WorkMonthId = personWorkMonth.Id; _uow.PersonTaskRepository.Insert(personTask); _uow.Save(); return Json(new { Result = "OK" }); } return Json(new { Result = "ERROR" }); } catch (Exception ex) { return Json(new { Result = "ERROR", Exception = ex }); } }
public async Task<JsonResult> Edit(PersonTaskViewModel personTaskViewModel) { if (ModelState.IsValid) { TimeSpan timeZoneOffset = GetCurrentTimeZoneOffset(); personTaskViewModel.StartTime = _timeZoneHelper.GetUtcDateTime(personTaskViewModel.StartDateValue, personTaskViewModel.StartTimeValue, timeZoneOffset); var personTask = _dataMapper.GetWrapper<PersonTask, PersonTaskViewModel>(personTaskViewModel); personTask.Project = await Task.Run(() => _uow.ProjectRepository.GetById(personTaskViewModel.ProjectId)); _uow.PersonTaskRepository.Update(personTask); _uow.Save(); return Json(new { Result = "OK" }); } return Json(new { Result = "ERROR" }); }