예제 #1
0
        public IActionResult Edit(int id)
        {
            ViewBag.Title = "Edit";

            var wish = _service.GetByID(id, _user.Id);

            if (wish.UserID != _user.Id)
            {
                ShowStatusMessage(MessageTypeEnum.warning, "This wish cannot be edited by another user.", "Edit Failure");
                return(RedirectToAction("Index", "Wish"));
            }
            var model = new WishFormModel
            {
                Categories =
                    new SelectList(
                        _service.GetAll(_user.Id)
                        .OrderBy(z => z.ItemType)
                        .GroupBy(x => new { x.ItemType, x.Category })
                        .Select(y => y.First()), "Category", "Category", string.Empty, "ItemType"),
                //_service.GetAll(_user.Id).Where(x => !string.IsNullOrWhiteSpace(x.Category)).Select(y => new SelectListItem
                //{
                //	Group = new SelectListGroup { Name = y.ItemType.ToString() },
                //	Text = y.Category,
                //	Value = y.Category,
                //	Selected = wish.Category == y.Category
                //}).OrderBy(z => z.Group.Name).ToList(),
                Wish = wish
            };

            return(View(model));
        }