Exemple #1
0
        public async Task <IActionResult> CreateAsync()
        {
            LeaveCreateIndexViewModel vm = new LeaveCreateIndexViewModel();

            vm.MyLeaves = await GetMyLeaves();

            return(View(vm));
        }
Exemple #2
0
        public async Task <IActionResult> CreateAsync([Bind(Prefix = "LeaveViewModel")] LeaveViewModel leaveVm)
        {
            LeaveCreateIndexViewModel vm = new LeaveCreateIndexViewModel();

            vm.LeaveViewModel = leaveVm;

            if (!ModelState.IsValid)
            {
                vm.MyLeaves = await GetMyLeaves();

                return(View(vm));
            }
            var leave = leaveVm.ToModel();

            leave.OwnerId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            _context.Leaves.Add(leave);
            await _context.SaveChangesAsync();

            return(LocalRedirect("~/")
                   .WithSuccess("hurray", $"new {EnumHelper<LeaveType>.GetDisplayValue(leave.Type)} created"));
        }