public async Task <IActionResult> UpdateAsync([FromRoute] Guid id, [FromBody] HostDto dto) { dto.Id = id; await _hostsService.UpdateAsync(dto); return(NoContent()); }
public async Task <ActionResult> AddAsync(HostDto dto) { await _hostService.AddAsync(dto); AddResourceIdHeader(dto.Id); return(CreatedAtAction(nameof(Get), new { id = dto.Id }, null)); }
public static DAL.Host ToDAL(HostDto hostDto) { if (hostDto is null) { return(null); } return(new DAL.Host() { BirthDate = hostDto.BirthDate, HostTextDetails = hostDto.HostTextDetails, HostID = hostDto.HostID, gender = hostDto.gender, HostEmail = hostDto.HostEmail, HostName = hostDto.HostName, HostTel = hostDto.HostTel, //User= new DAL.User() //{ // UserId=hostDto.UserID, // UserName=hostDto.UserName, // UserPassword=hostDto.UserPassword //} // User=User.ToDAL(hostDto.UserDto) // LocationHosts=hostDto. }); }
public HttpResponseMessage Put(int id, HostDto hostDto) { try { using (var unitOfWork = new UnitOfWork()) { var host = unitOfWork.HostRepository.Get(id); if (host == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Host id not found")); } host.Name = hostDto.Name; unitOfWork.Commit(); return(Request.CreateResponse(HttpStatusCode.OK, hostDto)); } } catch (Exception ex) { IocUnityContainer.Instance.Resolve <ILogManager>().DefaultLogger.Error.Write(ex.Message, ex); throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
/// <inheritdoc/> public async Task UpdateAsync( IWho who, IAuditHeaderWithAuditDetails auditHeader, IHost host) { this.logger.LogTrace( "ENTRY {Method}(who, host) {@Who} {@Host}", nameof(this.UpdateAsync), who, host); HostDto dto = HostDto.ToDto(host); HostDto original = await this.context.FindAsync <HostDto>(host.Id) .ConfigureAwait(false); Audit.AuditUpdate(auditHeader, dto.Id, original, dto); this.context.Entry(original).CurrentValues.SetValues(dto); await this.context.SaveChangesAsync().ConfigureAwait(false); this.logger.LogTrace( "EXIT {Method}(who) {@Who}", nameof(this.UpdateAsync), who); }
private void ValidateHost(HostDto host) { if (host.FilledSlots > host.FilledSlots) { Logger.Error(ErrorMessages.ErrorsummarizingHosts); Notifications.Add(ErrorMessages.ErrorsummarizingHosts); } }
public IHttpActionResult UpdateHost(HostDto hostDto) { if (BL.ManageHost.UpdateHost(hostDto) != null) { // return Ok(BL.ManageHost.GetHost(hostDto.UserID)); return(Ok(hostDto)); } return(StatusCode(HttpStatusCode.InternalServerError)); }
public async Task AddAsync(HostDto dto) { dto.Id = Guid.NewGuid(); await _hostRepository.AddAsync(new Host() { Id = dto.Id, Name = dto.Name, Description = dto.Description }); }
public IHttpActionResult GetHost([FromUri] int id) { HostDto h = BL.ManageHost.GetHost(id); if (h != null) { return(Ok(h)); } return(InternalServerError()); }
public async Task UpdateAsync(HostDto dto) { var host = await _hostsRepository.GetAsync(dto.Id); if (host is null) { throw new HostNotFoundException(dto.Id); } host.Name = dto.Name; host.Description = dto.Description; await _hostsRepository.UnitOfWork.SaveChangesAsync(); }
public async Task <ActionResult <HostDto> > UpdateHost(int id, [FromBody] HostDto host) { if (id != host.Id) { return(BadRequest()); } if (!HostLogic.HostExists(id)) { return(NotFound()); } HostDto returnHost = await HostLogic.UpdateHostAsync(host); return(Ok(returnHost)); }
private async void lstHosts_DoubleClick(object sender, EventArgs e) { tabControlPanel.SelectedIndex = 1; _selectedHost = _hosts[lstHosts.SelectedIndex]; _selectedPlaylist = null; UpdateHeaderText(); lstPlaylists.Items.Clear(); lstPlaylists.Enabled = false; lstPlaylists.Items.Add("loading..."); await GetUserPlaylists(); await _soulstoneHub.Invoke("GetPlayerStatus", _selectedHost.Id); ShowPlaylistsList(); }
public void Ensure_FleetService_LoadFleet_Formats_ReadFile_Into_List_Of_Lines_If_Seperator_Is_CaridgeReturn() { var repo = A.Fake<IFileRepository>(); var logger = A.Fake<ILogger>(); string host = "1,M5,0,1,1,0,1" ; var expectedResult = new HostDto(){ Id= 1, Instance="M1", N = 5, FilledSlots = 3 }; var hostValidation = new HostValidation(logger); var result = hostValidation.ValidateAndCreateHost(host); Assert.AreEqual(expectedResult.FilledSlots, result.FilledSlots); }
public IHttpActionResult AddHost(HostDto hostDto) { if (BL.ManageUser.IsExists(hostDto.UserName)) { // return Request.CreateResponse(HttpStatusCode.NotFound, err); return(BadRequest("user name alredy exists")); } HostDto h = BL.ManageHost.SaveHost(hostDto); if (h != null) { // return Ok(BL.ManageHost.GetHost(hostDto.UserID)); return(Ok(new UserDto() { UserID = h.HostID, UserName = h.UserName, UserPassword = h.HostPassword, UserStaus = Status.Host })); } return(StatusCode(HttpStatusCode.InternalServerError)); }
public async Task Get_WhenUserIsAskingForStrangerInformation_ReturnUnauthorized() { var expectedResultValue = new HostDto { Id = userId }; this.mediatorMock .Setup(m => m.Send(It.IsAny <IRequest <HostDto> >(), It.IsAny <CancellationToken>())) .ReturnsAsync(expectedResultValue); var controller = this.CreateController(this.userId + 10, RoleNames.Host); // Act var result = await controller.Get(this.userId); // Assert var unauthorizedResult = Assert.IsAssignableFrom <UnauthorizedResult>(result); this.mediatorMock.Verify(m => m.Send(It.IsAny <IRequest <HostDto> >(), It.IsAny <CancellationToken>()), Times.Never); }
public static async Task <HostDto> UpdateHostAsync(HostDto host) { Host hostToUpdate = new Host { Id = host.Id, Name = host.Name, TwitterHandle = host.TwitterHandle, PodcastHosts = new List <PodcastHost>() }; _context.Entry(hostToUpdate).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(await _context.Hosts.Select(x => new HostDto { Id = x.Id, Name = x.Name, TwitterHandle = x.TwitterHandle }).FirstOrDefaultAsync(x => x.Id == host.Id)); }
public async Task Get_WhenUserIsAskingForItsOwnInformation_ReturnHostDtoFromMediator() { // Arrange var expectedResultValue = new HostDto { Id = userId }; this.mediatorMock .Setup(m => m.Send(It.IsAny <IRequest <HostDto> >(), It.IsAny <CancellationToken>())) .ReturnsAsync(expectedResultValue); var controller = this.CreateController(this.userId, RoleNames.Host); // Act var result = await controller.Get(this.userId); // Assert var okResult = Assert.IsAssignableFrom <OkObjectResult>(result); var value = Assert.IsType <HostDto>(okResult.Value); Assert.Equal(expectedResultValue, value); }
public void CanListHosts() { // Establish Context var viewModelToExpect = new SearchResultFormViewModel <HostDto, HostSearchRequest>(); viewModelToExpect.PageResultItems = new List <HostDto>(); var hostDto = new HostDto(); viewModelToExpect.PageResultItems.Add(hostDto); hostSearchManagementService.Expect(r => r.CreateFormViewModel()) .Return(viewModelToExpect); // Act ViewResult result = hostsController.Index().AssertViewRendered(); // Assert result.ViewData.Model.ShouldNotBeNull(); (result.ViewData.Model as SearchResultFormViewModel <HostDto, HostSearchRequest>).ShouldNotBeNull(); (result.ViewData.Model as SearchResultFormViewModel <HostDto, HostSearchRequest>).PageResultItems.Count. ShouldBeGreaterThan(0); }
public static DAL.User ToUserDAL(HostDto hostDto) { if (hostDto is null) { return(null); } return(new DAL.User() { UserPassword = hostDto.HostPassword, UserName = hostDto.UserName, //UserId = hostDto.UserID, Host = new DAL.Host() { BirthDate = hostDto.BirthDate, HostTextDetails = hostDto.HostTextDetails, HostTel = hostDto.HostTel, gender = hostDto.gender, HostEmail = hostDto.HostEmail, HostID = hostDto.HostID, HostName = hostDto.HostName, } }); }
/// <inheritdoc/> public async Task CreateAsync( IWho who, IAuditHeaderWithAuditDetails auditHeader, IHost host) { this.logger.LogTrace( "ENTRY {Method}(who, organisation) {@Who} {@Host}", nameof(this.CreateAsync), who, host); HostDto dto = HostDto.ToDto(host); this.context.Hosts.Add(dto); await this.context.SaveChangesAsync().ConfigureAwait(false); Audit.AuditCreate(auditHeader, dto, dto.Id); this.logger.LogTrace( "EXIT {Method}(who) {@Who}", nameof(this.CreateAsync), who); }
public HttpResponseMessage Post(HostDto hostDto) { try { using (var unitOfWork = new UnitOfWork()) { var host = new Host { Name = hostDto.Name }; unitOfWork.HostRepository.Save(host); unitOfWork.Commit(); hostDto.Id = host.Id; return(Request.CreateResponse(HttpStatusCode.Created, hostDto)); } } catch (Exception ex) { IocUnityContainer.Instance.Resolve <ILogManager>().DefaultLogger.Error.Write(ex.Message, ex); throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public static HostDto UpdateHost(HostDto hostDto) { return(Host.ToDTO(DAL.ManageHost.UpdateHost(Host.ToDAL(hostDto)))); }
/// <summary> /// שמירת מארח /// </summary> /// <param name="hostDto"></param> /// <returns></returns> public static HostDto SaveHost(HostDto hostDto) { return(Host.ToDTO(DAL.ManageHost.SaveHost(Host.ToUserDAL(hostDto)))); }