Ejemplo n.º 1
0
        public async Task <ClientServiceModel> GetByOrganisationAsync(GetClientByOrganisationServiceModel model)
        {
            var clients = from c in this.context.Clients
                          where c.OrganisationId == model.Id.Value && c.IsActive
                          select new ClientServiceModel
            {
                Id    = c.Id,
                Name  = c.Name,
                Email = c.Email,
                CommunicationLanguage = c.Language,
                LastModifiedDate      = c.LastModifiedDate,
                CreatedDate           = c.CreatedDate
            };

            return(await clients.FirstOrDefaultAsync());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetByOrganisation()
        {
            var sellerClaim  = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim);
            var serviceModel = new GetClientByOrganisationServiceModel
            {
                Id = GuidHelper.ParseNullable(sellerClaim?.Value),
            };

            var validator        = new GetClientByOrganisationModelValidator();
            var validationResult = await validator.ValidateAsync(serviceModel);

            if (validationResult.IsValid)
            {
                var client = await this.clientsService.GetByOrganisationAsync(serviceModel);

                if (client != null)
                {
                    var response = new ClientResponseModel
                    {
                        Id    = client.Id,
                        Email = client.Email,
                        Name  = client.Name,
                        CommunicationLanguage = client.CommunicationLanguage,
                        LastModifiedDate      = client.LastModifiedDate,
                        CreatedDate           = client.CreatedDate
                    };

                    return(this.StatusCode((int)HttpStatusCode.OK, response));
                }
                else
                {
                    return(this.StatusCode((int)HttpStatusCode.NotFound));
                }
            }

            throw new CustomException(string.Join(ErrorConstants.ErrorMessagesSeparator, validationResult.Errors.Select(x => x.ErrorMessage)), (int)HttpStatusCode.UnprocessableEntity);
        }