示例#1
0
        public async Task <ClientServiceModel> GetAsync(GetClientServiceModel model)
        {
            var clients = from c in this.context.Clients
                          where c.SellerId == model.OrganisationId.Value && c.Id == model.Id && 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());
        }
示例#2
0
        public async Task <IActionResult> Get(Guid?id)
        {
            var sellerClaim = this.User.Claims.FirstOrDefault(x => x.Type == AccountConstants.Claims.OrganisationIdClaim);

            var serviceModel = new GetClientServiceModel
            {
                Id             = id,
                Language       = CultureInfo.CurrentCulture.Name,
                OrganisationId = GuidHelper.ParseNullable(sellerClaim?.Value)
            };

            var validator = new GetClientModelValidator();

            var validationResult = await validator.ValidateAsync(serviceModel);

            if (validationResult.IsValid)
            {
                var client = await this.clientsService.GetAsync(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);
        }