public IHttpActionResult LeaveSave(LeaveViewModel model)
        {
            model.CreatedBy = User.Identity.GetUserId <long>();
            var responseId = _leaveService.LeaveInsert(model.ToModel());

            return(Ok(responseId.SuccessResponse("Leave Saved successfully")));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> EditAsync(int id, LeaveViewModel leaveVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(leaveVm));
            }
            var leave = await _context.Leaves
                        .Include(l => l.Owner)
                        .Include(l => l.Reply)
                        .AsNoTracking()
                        .FirstOrDefaultAsync(l => l.Id == id);

            if (leave == null)
            {
                return(BadRequest());
            }
            var authorizationResult = await _authorizationService.AuthorizeAsync(User, leave, GetRequirementForLeave(leave));

            if (authorizationResult.Succeeded)
            {
                leave         = leaveVm.ToModel();
                leave.OwnerId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                _context.Entry(leave).State = EntityState.Modified;

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home").WithSuccess("hurray", $"leave with id {leave.Id} was updated"));
            }
            else if (User.Identity.IsAuthenticated)
            {
                return(new ForbidResult());
            }
            else
            {
                return(new ChallengeResult());
            }
        }
 public IHttpActionResult UpdateLeave(LeaveViewModel model)
 {
     _leaveService.LeaveUpdate(model.ToModel());
     return(Ok("Leave Updated successfully".SuccessResponse()));
 }