コード例 #1
0
        //[ValidateAntiForgeryToken]
        public IActionResult Create(CatchViewModel model)
        {
            var userByUserName = _userRepository.GetUserByUserName(User.Identity.Name);
            var userId         = userByUserName.Id;

            //int userId = int.Parse(uId);

            if (ModelState.IsValid)
            {
                var fishingGround = new FishingGround();

                fishingGround.Name     = model.FishingGroundName;
                fishingGround.Type     = model.FishingGroundType;
                fishingGround.ParishId = model.ParishId;

                var newCatch = new Catch();
                newCatch.Date          = model.Date;
                newCatch.Length        = model.Length;
                newCatch.Weight        = model.Weight;
                newCatch.Notes         = model.Notes;
                newCatch.FishId        = model.FishId;
                newCatch.UserId        = userId;
                newCatch.FishingGround = fishingGround;
                newCatch = _catchRepository.Add(newCatch);
                _catchRepository.Commit();

                return(RedirectToAction("Details", "Home", new { id = newCatch.Id }));
            }

            return(View(model));
        }
コード例 #2
0
        public IActionResult EditCatch(CatchViewModel fCatch)
        {
            var catchToEdit   = _catchRepository.Get(fCatch.Id);
            var fishingGround = _fishingGroundRepository.GetFishingGroundById(fCatch.FishingGroundId);

            if (ModelState.IsValid)
            {
                fishingGround.Id       = fCatch.FishingGroundId;
                fishingGround.Name     = fCatch.FishingGroundName;
                fishingGround.Type     = fCatch.FishingGroundType;
                fishingGround.ParishId = fCatch.ParishId;
                catchToEdit.Date       = fCatch.Date;
                catchToEdit.Length     = fCatch.Length;
                catchToEdit.Weight     = fCatch.Weight;
                catchToEdit.Notes      = fCatch.Notes;
                catchToEdit.FishId     = fCatch.FishId;


                catchToEdit.FishingGround = fishingGround;
                _catchRepository.UpdateCatch(catchToEdit);

                return(RedirectToAction("Details", "Home", new { id = catchToEdit.Id }));
            }

            fCatch.FishesSelectListItems   = GetFishesListItem();
            fCatch.ParishesSelectListItems = GetParischesListItem();

            return(View(fCatch));
        }
コード例 #3
0
        public IActionResult EditCatch(int id)
        {
            var model = _catchRepository.Get(id);

            if (model == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            CatchViewModel catchView = new CatchViewModel
            {
                Id = model.Id,
                FishingGroundId         = model.FishingGroundId,
                Date                    = model.Date,
                FishingGroundType       = model.FishingGround.Type,
                FishId                  = model.FishId,
                FishingGroundName       = model.FishingGround.Name,
                Length                  = model.Length,
                Weight                  = model.Weight,
                ParishId                = model.FishingGround.ParishId,
                Notes                   = model.Notes,
                ParishesSelectListItems = GetParischesListItem(),
                FishesSelectListItems   = GetFishesListItem()
            };

            return(View(catchView));
        }
コード例 #4
0
        //[ValidateAntiForgeryToken]
        public IActionResult Create()
        {
            var viewModel = new CatchViewModel();

            viewModel.FishesSelectListItems   = GetFishesListItem();
            viewModel.ParishesSelectListItems = GetParischesListItem();

            return(View(viewModel));
        }