Exemple #1
0
        public IActionResult Update(
            [Bind("Id, Title, Description, Executors, Status, Done, Fact")] DoUpdateViewModel model
            )
        {
            if (ModelState.IsValid)
            {
                var doForUpdate = _doService.GetDo(model.Id);

                if (doForUpdate != null)
                {
                    var updatingDo = new DoServiceModel
                    {
                        Id          = model.Id,
                        Title       = model.Title,
                        Description = model.Description,
                        Executors   = model.Executors,
                        Status      = model.Status,
                        Done        = model.Done,
                        Fact        = model.Fact
                    };

                    _doService.UpdateDo(updatingDo);

                    TempData["Message"] = "Задача " + model.Title + " успешно обновлена!";
                }

                return(RedirectToAction("Index"));
            }

            TempData["Message"] = "Задача " + model.Title + " не может быть обновлена";

            return(View(model));
        }
Exemple #2
0
        public IActionResult Create(
            [Bind("Title, Description, Executors, Plan")] DoCreateViewModel model
            )
        {
            if (ModelState.IsValid)
            {
                var newDo = new DoServiceModel
                {
                    Title       = model.Title,
                    Description = model.Description,
                    Executors   = model.Executors,
                    Plan        = int.Parse(model.Plan)
                };

                _doService.CreateDo(newDo);

                TempData["Message"] = "Задача " + newDo.Title + " успешно создана!";

                return(RedirectToAction("Index"));
            }

            TempData["Message"] = "Задача " + model.Title + " не может быть создана!";

            return(View(model));
        }
Exemple #3
0
        public IActionResult AddSubTask(int terminalId,
                                        [Bind("Title, Description, Executors, Plan")] DoCreateViewModel model
                                        )
        {
            var terminal = _doService.GetDo(terminalId);

            if (terminal == null)
            {
                throw new ValidationException("Терминальная задача не найдена");
            }

            if (ModelState.IsValid)
            {
                var newDo = new DoServiceModel
                {
                    Title       = model.Title,
                    Description = model.Description,
                    Executors   = model.Executors,
                    Plan        = int.Parse(model.Plan)
                };

                newDo = _doService.GetDo(_doService.CreateDo(newDo).Value);

                terminal.SubTasks.Add(newDo);
                _doService.UpdateDo(terminal);

                TempData["Message"] = "Подзадача " + newDo.Title + " успешно создана!";

                return(RedirectToAction("Index"));
            }

            TempData["Message"] = "Подзадача " + model.Title + " не может быть создана!";

            return(RedirectToAction("Index"));
        }
Exemple #4
0
 public DoUpdateViewModel(DoServiceModel model)
 {
     Id          = model.Id;
     Title       = model.Title;
     Description = model.Description;
     Executors   = model.Executors;
     Status      = model.Status;
     Done        = model.Done;
     Fact        = model.Fact;
 }
Exemple #5
0
        public DoListingViewModel(DoServiceModel model)
        {
            Id    = model.Id;
            Title = model.Title;

            if (model.SubTasks != null && model.SubTasks.Any())
            {
                SubTasks = model.SubTasks.Select(s => new DoListingViewModel(s)).ToList();
            }
            else
            {
                SubTasks = new List <DoListingViewModel>();
            }
        }
Exemple #6
0
        public void UpdateDo(DoServiceModel model)
        {
            var toDo = Data.ToDoes.FindByIdAsync(model.Id).Result;

            if (toDo == null)
            {
                throw new NotFindException("UpdateDo");
            }

            if (model.Status == DoStatus.Done)
            {
                CompleteTerminalTask(toDo);
            }
            else
            {
                toDo.Status = model.Status;
            }

            toDo.Title       = model.Title;
            toDo.Description = model.Description;
            toDo.Executors   = model.Executors;
            toDo.Plan        = model.Plan;
            toDo.Fact        = model.Fact;
            toDo.Done        = model.Done;

            if (model.SubTasks != null)
            {
                var subIds = model.SubTasks.Select(x => x.Id);
                var subs   = Data.ToDoes.AsQueryable()
                             .Where(x => subIds.Contains(x.Id));

                foreach (var item in subs)
                {
                    toDo.SubTasks.Add(item);
                }
            }


            Data.ToDoes.Update(toDo);
            Data.Save();
        }
Exemple #7
0
        public DoDetailsViewModel(DoServiceModel model)
        {
            Id          = model.Id;
            Title       = model.Title;
            Description = model.Description;
            Executors   = model.Executors;
            Status      = model.Status;
            Created     = model.Created;
            Done        = model.Done;
            Plan        = model.Plan;
            Fact        = model.Fact;

            if (model.SubTasks != null && model.SubTasks.Any())
            {
                SubTasks = model.SubTasks.Select(s => new DoDetailsViewModel(s)).ToList();
            }
            else
            {
                SubTasks = new List <DoDetailsViewModel>();
            }
        }
Exemple #8
0
        public int?CreateDo(DoServiceModel model)
        {
            try
            {
                var newDo = new Do
                {
                    Title       = model.Title,
                    Description = model.Description,
                    Executors   = model.Executors,
                    Status      = DoStatus.Created,
                    Created     = DateTime.Now,
                    Plan        = model.Plan
                };

                Data.ToDoes.Insert(newDo);
                Data.Save();
                return(newDo.Id);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #9
0
 public DoDeleteViewModel(DoServiceModel model)
 {
     Id          = model.Id;
     Title       = model.Title;
     Description = model.Description;
 }
Exemple #10
0
 public DoDescriptionViewModel(DoServiceModel model)
 {
     Id          = model.Id;
     Description = model.Description;
 }