예제 #1
0
        public async Task CreateMemberAsync(MemberDto member, Phone phone, Address address)
        {
            try
            {
                var dbPhone = await CreatePhone(phone);
                var addressId = await CreateAddress(address);
                var user = await DbContext.GetUserByEmailAsync(member.Email);
                var dbMember = new Member
                {
                    DateOfBirth = member.DoB,
                    Height = member.Height,
                    Sex = member.Sex,
                    Weight = member.Weight,
                    AddressId = addressId,
                    Address = address,
                    Phone = new List<Phone> { dbPhone },
                    User = user,
                    UserId = user?.Id,
                };

                await DbContext.CreateMemberAsync(dbMember);
            }
            catch (DbEntityValidationException ex)
            {
                
            }
            
        }
예제 #2
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;
        }