예제 #1
0
        public async Task <IActionResult> Create(StaffViewModel model)
        {
            var states = await _stateService.GetStates();

            var ranks = RankExtensions.GetRanks();

            if (ModelState.IsValid)
            {
                var response = await _staffService.AddStaff(model.FirstName, model.LastName, model.MiddleName,
                                                            model.ArmyNumber, model.PhoneNumber, model.Address, model.Rank, model.State, model.BirthDate,
                                                            model.RetirementDate);

                ViewBag.Error   = !response.Status;
                ViewBag.Message = response.Message;
                ViewBag.States  = new SelectList(states, "Key", "Value");
                ViewBag.Ranks   = new SelectList(ranks, "Key", "Value");
                return(View(new StaffViewModel()));
            }
            else
            {
                ViewBag.Error   = true;
                ViewBag.Message = "Kindly fill the form correctly!";
                ViewBag.States  = new SelectList(states, "Key", "Value", model.State);
                ViewBag.Ranks   = new SelectList(ranks, "Key", "Value", model.Rank);
                return(View(model));
            }
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id)
        {
            var staff = await _staffService.GetStaffAsync(id);

            if (staff == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                var states = await _stateService.GetStates();

                var ranks = RankExtensions.GetRanks();
                ViewBag.States = new SelectList(states, "Key", "Value", staff.StateId);
                ViewBag.Ranks  = new SelectList(ranks, "Key", "Value", staff.RankId);

                var viewModel = new StaffViewModel
                {
                    Rank      = staff.RankId, LastName = staff.LastName, FirstName = staff.FirstName,
                    State     = staff.StateId, ArmyNumber = staff.ArmyNumber, PhoneNumber = staff.PhoneNumber,
                    BirthDate = staff.BirthDate, RetirementDate = staff.RetirementDate,
                    Address   = staff.Address, MiddleName = staff.MiddleName, Id = staff.Id
                };
                return(View(viewModel));
            }
        }
예제 #3
0
        public async Task <IActionResult> Create()
        {
            var states = await _stateService.GetStates();

            ViewBag.States = new SelectList(states, "Key", "Value");
            var ranks = RankExtensions.GetRanks();

            ViewBag.Ranks = new SelectList(ranks, "Key", "Value");
            return(View());
        }