public async Task <IActionResult> Create(int id) { Socket socket = _socketRepository.GetSocketById(id); if (socket == null) { return(new NotFoundResult()); } TimeTask timeTask = new TimeTask { Socket = socket, SocketId = id, TimeStamp = DateTime.Today }; AuthorizationResult authorizationResult = await _authorizationService .AuthorizeAsync(User, timeTask, Operations.Create); if (!authorizationResult.Succeeded) { return(new ForbidResult()); } TimeTaskCreateViewModel timeTaskViewModel = _mapper.Map <TimeTaskCreateViewModel>(timeTask); return(View(timeTaskViewModel)); }
public IActionResult Create(TimeTaskCreateViewModel model) { if (model.TimeStamp.CompareTo(DateTime.Now.AddMinutes(1)) <= 0) { ModelState.AddModelError("", "Date must be minimum 1 minute in the future"); return(View(model)); } TimeTask timeTask = _mapper.Map <TimeTask>(model); _timeTaskRepository.CreateTimeTask(timeTask); _socketRepository.Savechanges(); string backgroundJobId = BackgroundJob.Schedule(() => ExecuteTimeTask(timeTask), timeTask.TimeStamp); timeTask.BackgroundJobId = backgroundJobId; _timeTaskRepository.EditTimeTask(timeTask); _socketRepository.Savechanges(); return(RedirectToRoute("TimeTask", new { id = model.SocketId })); }