예제 #1
0
 public async Task SaveRequest(RequestDto model)
 {
     var member = await DbContext.GetMemberByMemberIdAsync(model.CreatedByMember);
     var assignedToProvider = await DbContext.GetProviderByProviderIdAsync(model.AssignedProviderId);
     var requestProvider = await DbContext.GetProviderByProviderIdAsync(model.RequestProvider.ProviderId);
     var request = new Request
     {
         Comment = model.Comment,
         AssignedToProviderId = model.AssignedProviderId,
         AssignedToProvider = assignedToProvider,
         CreatedByMember = model.CreatedByMember,
         CreatedDt = model.CreatedDt,
         DueEndDt = model.DueEndDt,
         DueStartDt = model.DueStartDt,
         MemberCreator = member,
         Status = model.Status,
         ModifiedDt = DateTime.Now,
         RequestDescription = model.RequestDescription,
         Id = model.Id,
         RequestProvider = requestProvider,
         LockedByProvider = model.LockedByProvider,
         LockeDt = model.LockeDt,
     };
     await DbContext.SaveRequest(request);
 }
예제 #2
0
 public async Task SaveRequest(Request request)
 {
     Requests.AddOrUpdate(request);
     await SaveChangesAsync();
 }
예제 #3
0
        public async Task<ServiceResult> SubmitRequest(RequestDto model, MemberDto requestor)
        {
            var result = new ServiceResult();
            try
            {
                model.CreatedByMember = requestor.MemberId;
                if (model.DueEndDt <= model.DueStartDt)
                {
                    result.Success = false;
                    result.Messages = new List<string> { "End date is bigger than start date. Please change." };
                    return result;
                }
                var activeStatuses = new[] { RequestStatus.Locked, RequestStatus.Started, RequestStatus.Pending };

                var memberRequests = (await DbContext.GetRequestsByMemberIdAsync(requestor.MemberId)).Where(c => c.Status != RequestStatus.Closed).ToList();
                if (memberRequests.Any(memberRequest => (model.DueStartDt >= memberRequest.DueStartDt && model.DueStartDt <= memberRequest.DueEndDt ||
                                                        model.DueEndDt > memberRequest.DueStartDt && model.DueEndDt <= memberRequest.DueEndDt) && activeStatuses.Contains(memberRequest.Status)))
                {
                    result.Success = false;
                    result.Messages = new List<string> { "You have another request with crossing time interval please change time intervals." };
                    return result;
                }

                var member = await DbContext.GetMemberByMemberIdAsync(model.CreatedByMember);
                var assignedToProvider = await DbContext.GetProviderByProviderIdAsync(model.AssignedProviderId);
                var request = new Request
                {
                    Comment = model.Comment,
                    AssignedToProviderId = model.AssignedProviderId,
                    AssignedToProvider = assignedToProvider,
                    CreatedByMember = model.CreatedByMember,
                    CreatedDt = DateTime.Now,
                    DueEndDt = model.DueEndDt,
                    DueStartDt = model.DueStartDt,
                    MemberCreator = member,
                    Status = model.Status,
                    ModifiedDt = DateTime.Now,
                    RequestDescription = model.RequestDescription,
                };
                await DbContext.SaveRequest(request);
                result.Success = true;
                result.Messages = new List<string> { "Your request is successfully submited." };
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Messages = new List<string> { "Internal server error.", $"Exception is: {ex.ToString()}" };
            }

            return result;
        }