public async Task <IHttpActionResult> PutClientNoSecret(string id, ClientNoSecretDto client) { if (id != client.Id) { CustomException.ThrowBadRequestException($"Client id: {id} doesn't match."); } return(Ok(await ClientService.UpdateNoSecret(client))); }
public async Task <IHttpActionResult> PutMyClient(string id, ClientNoSecretDto client) { var userName = User.Identity.Name; if (!await ClientService.CheckUserClient(userName, id)) { CustomException.ThrowBadRequestException($"There is no client with id = {id} associated with user: {userName}."); } if (id != client.Id) { CustomException.ThrowBadRequestException($"Client id: {id} doesn't match."); } return(Ok(await ClientService.UpdateNoSecret(client))); }
public async Task <ClientNoSecretDto> UpdateNoSecret(ClientNoSecretDto dtoModel) { if (!await ExistsAsync(dtoModel.Id)) { CustomException.ThrowNotFoundException($"There is no client with clientId = {dtoModel.Id}."); } var client = await GetByIdAsync(dtoModel.Id); var clientSecret = client.ClientSecret; var clientDomain = ModelFactory.GetModel <Domain.Entity.Client.Client>(dtoModel); clientDomain.ClientSecret = clientSecret; await UnitOfWork.ClientRepository.Update(clientDomain); return(ModelFactory.GetModel <ClientNoSecretDto>(clientDomain)); }
public override TDto GetModel <TDto>(EntityBase domainEntity) { if (TypesEqual <TDto, ClientDto>()) { var clientEntity = (Domain.Entity.Client.Client)domainEntity; var model = new ClientDto { Active = clientEntity.Active, ClientSecret = clientEntity.ClientSecret, AllowedOrigin = clientEntity.AllowedOrigin, Username = clientEntity.Username, ApplicationType = clientEntity.ApplicationType, Id = clientEntity.Id, RefreshTokenLifeTime = clientEntity.RefreshTokenLifeTime }; if (RequestMessage != null) { AddLinks(model, "ClientRoute", "client", " - Administrators only"); model.Links.Add(new Link { Rel = "user clients - Administrators only", Href = Url.Link("UserClientsRoute", new { userName = model.Username }), Method = "GET" }); model.Links.Add(new Link { Rel = "put client no secret change - Administrators only", Href = Url.Link("PutClientNoSecretRoute", new { id = model.Id }), Method = "PUT" }); model.Links.Add(new Link { Rel = "Reset client secret - Administrators only", Href = Url.Link("ResetClientSecretRoute", null), Method = "POST" }); model.Links.Add(new Link { Rel = "my clients", Href = Url.Link("GetMyClientsRoute", null), Method = "GET" }); model.Links.Add(new Link { Rel = "my client", Href = Url.Link("GetMyClientsRoute", new { id = model.Id }), Method = "GET" }); model.Links.Add(new Link { Rel = "add new client", Href = Url.Link("AddClientRoute", null), Method = "POST" }); model.Links.Add(new Link { Rel = "reset my client secret", Href = Url.Link("ResetMyClientSecretRoute", null), Method = "POST" }); model.Links.Add(new Link { Rel = "edit my client", Href = Url.Link("PutMyClientRoute", new { id = model.Id }), Method = "PUT" }); } return(model as TDto); } if (TypesEqual <TDto, ClientByUserNameDto>()) { var clientEntity = (Domain.Entity.Client.Client)domainEntity; var model = new ClientByUserNameDto { Active = clientEntity.Active, AllowedOrigin = clientEntity.AllowedOrigin, ApplicationType = clientEntity.ApplicationType.ToString(), Id = clientEntity.Id, RefreshTokenLifeTime = clientEntity.RefreshTokenLifeTime, Links = new List <Link> { new Link { Rel = "my client", Href = Url.Link("GetMyClientsRoute", new { id = clientEntity.Id }), Method = "GET" }, new Link { Rel = "reset my client secret", Href = Url.Link("ResetMyClientSecretRoute", null), Method = "POST" }, new Link { Rel = "edit my client", Href = Url.Link("PutMyClientRoute", new { id = clientEntity.Id }), Method = "PUT" }, new Link { Rel = "add new client", Href = Url.Link("AddClientRoute", null), Method = "POST" } } }; return(model as TDto); } if (TypesEqual <TDto, ClientNoSecretDto>()) { var clientEntity = (Domain.Entity.Client.Client)domainEntity; var model = new ClientNoSecretDto { Active = clientEntity.Active, AllowedOrigin = clientEntity.AllowedOrigin, Username = clientEntity.Username, ApplicationType = clientEntity.ApplicationType, Id = clientEntity.Id, RefreshTokenLifeTime = clientEntity.RefreshTokenLifeTime }; if (RequestMessage != null) { AddLinks(model, "ClientRoute", "client", " - Administrators only"); model.Links.Add(new Link { Rel = "user clients - Administrators only", Href = Url.Link("UserClientsRoute", new { userName = model.Username }), Method = "GET" }); model.Links.Add(new Link { Rel = "put client no secret change - Administrators only", Href = Url.Link("PutClientNoSecretRoute", new { id = model.Id }), Method = "PUT" }); model.Links.Add(new Link { Rel = "Reset client secret - Administrators only", Href = Url.Link("ResetClientSecretRoute", null), Method = "POST" }); model.Links.Add(new Link { Rel = "my clients", Href = Url.Link("GetMyClientsRoute", null), Method = "GET" }); model.Links.Add(new Link { Rel = "my client", Href = Url.Link("GetMyClientsRoute", new { id = model.Id }), Method = "GET" }); model.Links.Add(new Link { Rel = "add new client", Href = Url.Link("AddClientRoute", null), Method = "POST" }); model.Links.Add(new Link { Rel = "reset my client secret", Href = Url.Link("ResetMyClientSecretRoute", null), Method = "POST" }); model.Links.Add(new Link { Rel = "edit my client", Href = Url.Link("PutMyClientRoute", new { id = model.Id }), Method = "PUT" }); } return(model as TDto); } return(null); }