// GET: People/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var person = await _context.Person.SingleOrDefaultAsync(m => m.PersonId == id);

            if (User.Identity.IsAuthenticated && User.Claims.First().Value == id.ToString() && person == null)
            {
                _context.Add(person = new Person {
                    PersonId = (Guid)id
                });
                await _context.SaveChangesAsync();
            }
            if (person == null)
            {
                return(NotFound());
            }
            var personVM = new PersonViewModel
            {
                Person   = person,
                TODOList = _context.PersonClaimsAbout.Where(u => u.UserId == id).Join(_context.TODO, p => p.PinnedToId, t => t.TodoId, (p, t) => new Tuple <Priviliges, TODO>(p.Privilege, t)).ToList()
            };

            personVM.TODOList.ForEach(t => t.Item2.Category = _context.Category.SingleOrDefault(c => c.CategoryId == t.Item2.CategoryId));

            return(View(personVM));
        }
        public async Task <IActionResult> Create([Bind("CategoryId,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("TodoId,CanBeStartedBefore,CategoryId,Deadline,Description,Name,Priority,StartDate,Status,StatusChangeDate,Type")] TODO tODO)
        {
            if (ModelState.IsValid)
            {
                tODO.TodoId           = Guid.NewGuid();
                tODO.StatusChangeDate = DateTime.Now;
                tODO.Status           = Statuses.Started;
                _context.Add(tODO);
                _context.Add(new PersonClaimsAbout {
                    UserId = Guid.Parse(User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value), PinnedToId = tODO.TodoId
                });
                _context.Add(new StatusChange {
                    Status = tODO.Status, TodoId = tODO.TodoId, ChangeDate = tODO.StatusChangeDate
                });
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryId", tODO.CategoryId);
            return(View(tODO));
        }