public int Approved(StatusRequestVM request) { var data = myContext.Requests.Where(r => r.Id == request.Id).FirstOrDefault(); if (data == null) { return(0); } else if (data.RequestStatus == RequestStatus.RejectByManager || data.RequestStatus == RequestStatus.RejectByHRD) { return(0); } if (data.RequestStatus == RequestStatus.OnProcess) { data.RequestStatus = RequestStatus.ApprovedByManager; data.ApprovedManager = "Approved"; myContext.Update(data); var request2 = new GeneralDapperRepository <RequestVM>(_configuration); _parameters.Add("@RoleId", 4); //role HR var result2 = request2.Query("SP_sendEmailHR", _parameters); var emailHR = result2.Email; SendEmail.Approvemanager(emailHR, data); } else if (data.RequestStatus == RequestStatus.ApprovedByManager) { var totoalDays = (data.EndDate.AddDays(1) - data.StartDate).TotalDays; var dataQuota = myContext.Requests.Where(e => e.Id == request.Id).FirstOrDefault(); dataQuota.Employee.RemainingQuota -= Convert.ToInt32(totoalDays); //kondisi cuti hamil myContext.Update(dataQuota); myContext.SaveChanges(); data.RequestStatus = RequestStatus.ApprovedByHRD; data.ApprovedHRD = "Approved"; myContext.Update(data); var request3 = new GeneralDapperRepository <RequestVM>(_configuration); var param = request.Id; _parameters.Add("@Id", param); var result3 = request3.Query("SP_EmailEmployee", _parameters); var emailEmployee = result3.Email; SendEmail.ApproveHR(emailEmployee, data); } myContext.SaveChanges(); return(1); }