public Task <Result <AppointmentCoreModel> > Get(Core.Models.BaseCoreModel coreModel) => Result <AppointmentCoreModel> .TryAsync(async() => { var result = await _repository.FirstOrDefaultAsNoTrackingAsync <Appointment>(s => s.Id == coreModel.Id, a => a.Invoice); if (!result.Success || result.Data == null) { return(Result <AppointmentCoreModel> .Failed(Error.WithCode(BaseErrorCodes.NotFound))); } var appointment = result.Data; LightUserModel user = null; LightUserModel representative = null; user = (await _membershipServiceApi.AuthAuthApiService.Setting(new BaseModel { Id = appointment.UserId })) .Data; representative = appointment.RepresentativeId != null ? (await _membershipServiceApi.AuthAuthApiService.Setting(new BaseModel { Id = appointment.RepresentativeId })).Data : null; var appointmentModel = new AppointmentCoreModel { Id = appointment.Id, Title = appointment.Title, Description = appointment.Description, User = user, Representative = representative, Date = appointment.Date, Type = appointment.Type, CreationDate = appointment.CreationDate, Duration = appointment.Duration, Invoice = appointment.Invoice != null ? new InvoiceCoreModel { Id = appointment.Invoice.Id, Amount = appointment.Invoice.Amount, Enabled = appointment.Invoice.Enabled, CreationDate = appointment.Invoice.CreationDate, Description = appointment.Invoice.Description, Title = appointment.Invoice.Title } : null, Approved = appointment.Approved }; return(Result <AppointmentCoreModel> .Successful(appointmentModel)); });
public Task <Result <TicketCoreModel> > Get(Core.Models.BaseCoreModel coreModel) => Result <TicketCoreModel> .TryAsync(async() => { var result = await _repository.FirstOrDefaultAsNoTrackingAsync <Ticket>(s => s.Id == coreModel.Id, t => t.Comment); if (!result.Success || result.Data == null) { return(Result <TicketCoreModel> .Failed(Error.WithData(1000, new[] { "Ticket Not Found" }))); } var ticket = result.Data; var userIds = new List <Guid> { ticket.UserId }; if (ticket.RepresentativeId.HasValue) { userIds.Add(ticket.RepresentativeId.Value); } userIds.AddRange(ticket.Comment != null ? ticket.Comment.Select(c => c.UserId).ToList() : new List <Guid>()); var users = (await _membershipServiceApi.SystemUserApiService.ListByIds(userIds)).Data; var ticketModel = new TicketCoreModel { Id = ticket.Id, Title = ticket.Title, Text = ticket.Text, User = users.FirstOrDefault(u => u.Id == ticket.UserId), Representative = ticket.RepresentativeId.HasValue ? users.FirstOrDefault(u => u.Id == ticket.RepresentativeId.Value) : null, BlobId = ticket.BlobId, CreationDate = ticket.CreationDate, Priority = (TicketPriority)ticket.Priority, Active = ticket.Active, Comment = ticket.Comment?.Select(c => new CommentCoreModel { Id = c.Id, BlobId = c.BlobId, CreationDate = c.CreationDate, Text = c.Text, User = users.FirstOrDefault(u => u.Id == c.UserId) }).ToList(), }; return(Result <TicketCoreModel> .Successful(ticketModel)); });