public async Task <IActionResult> Index(long?Id, long?IdOwner, string name) //Show collection Nodes for one StageTask { bool userExists = CheckUser(); if (!userExists) { return(RedirectToAction("Signin", "Account")); } if (Id == null || IdOwner == null || name == null) { return(NotFound()); } StageTask stage = null; try { await Task.Run(() => { stage = new StageUtils().GetOneStage(_context, (long)Id); }); } catch { return(NotFound()); } if (stage == null) { return(NotFound()); } if (name.Length < 6) { return(NotFound()); } string firstFiveChar = new string(name.Take(5).ToArray()); if ("Stage".CompareTo(firstFiveChar) != 0) { return(NotFound()); } string numbers = new string(name.Skip(5).ToArray()); long number; try { number = Int64.Parse(numbers); } catch (FormatException) { return(NotFound()); } int count_stage; try { count_stage = _context.StageTasks.Where(s => s.IdOwner == IdOwner).Count(); } catch (Exception) { return(NotFound()); } if (number > count_stage) { return(NotFound()); } int sizePage = 10; int count; try { count = _context.NodeStages.Where(n => n.IdOwner == Id).Count(); } catch (Exception) { return(NotFound()); } int totalPages; int lastPageSize; try { totalPages = (int)Math.Ceiling((count / (double)sizePage)); lastPageSize = count % sizePage; } catch (Exception) { return(NotFound()); } ViewBag.NameStage = name; ViewBag.IdOwner = IdOwner; ViewBag.IdStage = Id; string nameTask = null; try { nameTask = await _context.BoardTasks.Where(t => t.Id == IdOwner).Select(t => t.NameTask).FirstOrDefaultAsync(); } catch (Exception) { return(NotFound()); } if (nameTask == null) { return(NotFound()); } ViewBag.NameTask = nameTask; ViewBag.TotalPages = totalPages; var list_node = await _context.NodeStages.Where(n => n.IdOwner == Id).Skip((1 - 1) * sizePage).Take(sizePage).ToListAsync(); return(View(list_node)); }
public async Task <IActionResult> CreateStage([Bind("IdOwner,ContentStage,DateFinished")] StageTask stageTask, string date_create) //CreateStage { bool userExists = CheckUser(); if (!userExists) { return(RedirectToAction("Signin", "Account")); } double localDate = Convert.ToDouble(date_create); stageTask.DateCreated = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds(localDate); // stageTask.DateCreated = ConvertStringToDateTime(date_create); //AddSeconds(localDate); BoardTask boardTask = null; try { await Task.Run(() => { boardTask = new BoardTaskUtils().GetBoardTask(_context, stageTask.IdOwner); }); } catch (Exception) { return(NotFound()); } if (boardTask == null) { return(NotFound()); } if ((boardTask.DateFinished.CompareTo(stageTask.DateFinished)) < 0) { ModelState.AddModelError("DateFinished", "Дата окончния не может быть позже даты окончния задачи"); } if ((stageTask.DateCreated.CompareTo(stageTask.DateFinished)) > 0) { ModelState.AddModelError("DateFinished", "Дата окончния меньше текущей"); } if (ModelState.IsValid) { stageTask.NameStage = "Stage"; try { await Task.Run(() => { new GeneralActions().AddNewObject(_context, stageTask); }); return(RedirectToAction("Details", "BoardTasks", new { id = stageTask.IdOwner })); } catch (Exception) { return(NotFound()); } } ViewData["IdOwner"] = stageTask.IdOwner; return(View(stageTask)); }