Ejemplo n.º 1
0
        public async Task <IActionResult> ApproveLeave([FromBody] PostApproveLeave postApprove)
        {
            if (postApprove == null)
            {
                return(Json(new
                {
                    msg = "No Data"
                }
                            ));
            }

            var orgId = getOrg();
            var organisationDetails = _context.Organisations.Where(x => x.Id == orgId).FirstOrDefault();


            try
            {
                var leave = _context.Leaves.Where(x => x.Id == postApprove.Id).Include(c => c.EmployeeDetail).FirstOrDefault();
                leave.Comment     = postApprove.Comment;
                leave.ApproveDate = DateTime.Now;
                leave.Status      = "Approved";

                _context.Update(leave);
                _context.SaveChanges();



                var response = _emailSender.SendGridLeaveApprovalAsync(leave.EmployeeDetail.Email, "Approved Leave Request", "/EmployeeProfile/Leave", leave.EmployeeDetail.FirstName, "approvalLeave", organisationDetails.OrganisationName, leave);

                StatusMessage = "Leave has been successfully Approved!.";

                return(Json(new
                {
                    msg = "Success"
                }
                            ));
            }
            catch (Exception ee)
            {
            }

            return(Json(
                       new
            {
                msg = "Fail"
            }));
        }
        public async Task <IActionResult> DeclineLeave([FromBody] PostApproveLeave postApprove)
        {
            if (postApprove == null)
            {
                return(Json(new
                {
                    msg = "No Data"
                }
                            ));
            }

            var orgId = getOrg();



            try
            {
                var leave = _context.Leaves.Where(x => x.Id == postApprove.Id).FirstOrDefault();
                leave.Comment     = postApprove.Comment;
                leave.ApproveDate = DateTime.Now;
                leave.Status      = "Declined";

                _context.Update(leave);
                _context.SaveChanges();

                StatusMessage = "Leave has been successfully Declined!.";

                return(Json(new
                {
                    msg = "Success"
                }
                            ));
            }
            catch (Exception ee)
            {
            }

            return(Json(
                       new
            {
                msg = "Fail"
            }));
        }