public static string DeleteLeaveRequest(HrmContext ctx, int id) { var request = ctx.DbContext.LeaveRequests.Find(id); if (!request.CanDelete()) throw new Exception($"{request.State.ToString()} can't not be deleted"); ctx.DbContext.LeaveRequests.Remove(request); return "success"; }
public static LeaveRequest CommentLeaveRequest(HrmContext ctx, LeaveRequestComment comment) { var target = ctx.DbContext.LeaveRequests.Find(comment.RequestId); if (target == null) throw new GraphQL.ExecutionError("request not exists"); comment.Type = CommentType.Comment; ctx.DbContext.Add(comment); return target; }
public static LeaveRequest ApproveLeaveRequest(HrmContext ctx, LeaveRequestComment comment) { var target = ctx.DbContext.LeaveRequests.Find(comment.RequestId); var canApprove = target.CanApproveBy(ctx.UserContext.Identity.Name); if (!canApprove.able) throw new GraphQL.ExecutionError(canApprove.reason); comment.Type = CommentType.Approve; target.State = LeaveRequestState.Processing; ctx.DbContext.Add(comment); return target; }
public static LeaveRequest CompleteLeaveRequest(HrmContext ctx, int id) { var leaveRequst = ctx.DbContext.LeaveRequests.Find(id); if (!leaveRequst.CanBalance()) throw new Exception($"the leave request can't be balanced"); var balance = new LeaveBalance() { Value = -ctx.Holidays.GetWorkHours(leaveRequst.Start.Value, leaveRequst.End.Value), OwnerId = leaveRequst.RequestIssuerId, Description = $"A completed Leave Request Start from {leaveRequst.Start.Value}", SnapShotData = JsonConvert.SerializeObject(new { requestId = leaveRequst.Id, requestFrom = leaveRequst.Start, requestTo = leaveRequst.End, type = leaveRequst.Type.ToString(), approves = leaveRequst.Comments .Select(x => new { x.Content, x.CreatedOn, x.CreatedBy, Type = x.Type.ToString() }) .ToList(), }) }; balance.RequestRelations.Add(new RequestBalanceRelation() { Balance = balance, RequestId = id }); ctx.DbContext.LeaveBalances.Add(balance); ctx.DbContext.LeaveRequestComments.Add(new LeaveRequestComment() { Content = "Completed", Type = CommentType.Comment, RequestId = leaveRequst.Id }); leaveRequst.State = LeaveRequestState.Completed; return leaveRequst; }
public static LeaveBalance CreateLeaveBalance(HrmContext ctx, LeaveBalance balance) { ctx.DbContext.Add(balance); return balance; }
public static LeaveRequest CreateLeaveRequest(HrmContext ctx, LeaveRequest request) { request.RequestIssuerId = ctx.UserContext.Identity.Name; ctx.DbContext.LeaveRequests.Add(request); return request; }