public virtual ApiLinkLogServerResponseModel MapEntityToModel( LinkLog item) { var model = new ApiLinkLogServerResponseModel(); model.SetProperties(item.Id, item.DateEntered, item.LinkId, item.Log); if (item.LinkIdNavigation != null) { var linkIdModel = new ApiLinkServerResponseModel(); linkIdModel.SetProperties( item.LinkIdNavigation.Id, item.LinkIdNavigation.AssignedMachineId, item.LinkIdNavigation.ChainId, item.LinkIdNavigation.DateCompleted, item.LinkIdNavigation.DateStarted, item.LinkIdNavigation.DynamicParameters, item.LinkIdNavigation.ExternalId, item.LinkIdNavigation.LinkStatusId, item.LinkIdNavigation.Name, item.LinkIdNavigation.Order, item.LinkIdNavigation.Response, item.LinkIdNavigation.StaticParameters, item.LinkIdNavigation.TimeoutInSeconds); model.SetLinkIdNavigation(linkIdModel); } return(model); }
public virtual BOLinkLog MapEFToBO( LinkLog ef) { var bo = new BOLinkLog(); bo.SetProperties( ef.Id, ef.DateEntered, ef.LinkId, ef.Log); return(bo); }
public virtual LinkLog MapBOToEF( BOLinkLog bo) { LinkLog efLinkLog = new LinkLog(); efLinkLog.SetProperties( bo.DateEntered, bo.Id, bo.LinkId, bo.Log); return(efLinkLog); }
public void MapModelToEntity() { var mapper = new DALLinkLogMapper(); ApiLinkLogServerRequestModel model = new ApiLinkLogServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A"); LinkLog response = mapper.MapModelToEntity(1, model); response.DateEntered.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.LinkId.Should().Be(1); response.Log.Should().Be("A"); }
public virtual async Task <ApiLinkLogServerResponseModel> Get(int id) { LinkLog record = await this.LinkLogRepository.Get(id); if (record == null) { return(null); } else { return(this.DalLinkLogMapper.MapEntityToModel(record)); } }
public void MapEntityToModelList() { var mapper = new DALLinkLogMapper(); LinkLog item = new LinkLog(); item.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A"); List <ApiLinkLogServerResponseModel> response = mapper.MapEntityToModel(new List <LinkLog>() { { item } }); response.Count.Should().Be(1); }
public void MapEntityToModel() { var mapper = new DALLinkLogMapper(); LinkLog item = new LinkLog(); item.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A"); ApiLinkLogServerResponseModel response = mapper.MapEntityToModel(item); response.DateEntered.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be(1); response.LinkId.Should().Be(1); response.Log.Should().Be("A"); }
public void MapEFToBOList() { var mapper = new DALLinkLogMapper(); LinkLog entity = new LinkLog(); entity.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A"); List <BOLinkLog> response = mapper.MapEFToBO(new List <LinkLog>() { entity }); response.Count.Should().Be(1); }
public void MapEFToBO() { var mapper = new DALLinkLogMapper(); LinkLog entity = new LinkLog(); entity.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A"); BOLinkLog response = mapper.MapEFToBO(entity); response.DateEntered.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be(1); response.LinkId.Should().Be(1); response.Log.Should().Be("A"); }
public void MapBOToEF() { var mapper = new DALLinkLogMapper(); var bo = new BOLinkLog(); bo.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A"); LinkLog response = mapper.MapBOToEF(bo); response.DateEntered.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Id.Should().Be(1); response.LinkId.Should().Be(1); response.Log.Should().Be("A"); }
public virtual LinkLog MapModelToEntity( int id, ApiLinkLogServerRequestModel model ) { LinkLog item = new LinkLog(); item.SetProperties( id, model.DateEntered, model.LinkId, model.Log); return(item); }
public async Task <string> CreateLinkNote(LinkCreateModel inputModel) { NoteFile file = await _context.NoteFile .SingleAsync(p => p.NoteFileName == inputModel.linkedfile); if (file == null) { return("Target file does not exist"); } // check for acceptance if (!await AccessManager.TestLinkAccess(_context, file, "")) { return("Access Denied"); } inputModel.header.NoteFileId = file.Id; inputModel.header.ArchiveId = 0; inputModel.header.BaseNoteId = 0; inputModel.header.Id = 0; inputModel.header.NoteContent = null; inputModel.header.NoteFile = null; inputModel.header.NoteOrdinal = 0; inputModel.header.ResponseOrdinal = 0; inputModel.header.ResponseCount = 0; var tags = Tags.ListToString(inputModel.tags); NoteHeader nh = await NoteDataManager.CreateNote(_context, null, inputModel.header, inputModel.content.NoteBody, tags, inputModel.content.DirectorMessage, true, true); if (nh == null) { return("Remote note create failed"); } LinkLog ll = new LinkLog() { Event = "Ok", EventTime = DateTime.UtcNow, EventType = "RcvdCreateBaseNote" }; _context.LinkLog.Add(ll); await _context.SaveChangesAsync(); return("Ok"); }
public virtual async Task <CreateResponse <ApiLinkLogServerResponseModel> > Create( ApiLinkLogServerRequestModel model) { CreateResponse <ApiLinkLogServerResponseModel> response = ValidationResponseFactory <ApiLinkLogServerResponseModel> .CreateResponse(await this.LinkLogModelValidator.ValidateCreateAsync(model)); if (response.Success) { LinkLog record = this.DalLinkLogMapper.MapModelToEntity(default(int), model); record = await this.LinkLogRepository.Create(record); response.SetRecord(this.DalLinkLogMapper.MapEntityToModel(record)); await this.mediator.Publish(new LinkLogCreatedNotification(response.Record)); } return(response); }
public async void Get_ShouldReturnRecords() { var mock = new ServiceMockFacade <ILinkLogService, ILinkLogRepository>(); var record = new LinkLog(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new LinkLogService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.LinkLogModelValidatorMock.Object, mock.DALMapperMockFactory.DALLinkLogMapperMock); ApiLinkLogServerResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public virtual async Task <UpdateResponse <ApiLinkLogServerResponseModel> > Update( int id, ApiLinkLogServerRequestModel model) { var validationResult = await this.LinkLogModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { LinkLog record = this.DalLinkLogMapper.MapModelToEntity(id, model); await this.LinkLogRepository.Update(record); record = await this.LinkLogRepository.Get(id); ApiLinkLogServerResponseModel apiModel = this.DalLinkLogMapper.MapEntityToModel(record); await this.mediator.Publish(new LinkLogUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiLinkLogServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiLinkLogServerResponseModel> .UpdateResponse(validationResult)); } }
public async Task<string> ProcessLinkAction(long linkId) { LinkQueue q; try { q = db.LinkQueue.SingleOrDefault(p => p.Id == linkId); } catch (Exception ex) { return ex.Message; } if (q == null) { return "Job not in Queue"; } NoteFile notefile = db.NoteFile.SingleOrDefault(p => p.Id == q.LinkedFileId); string notefilename = notefile.NoteFileName; HttpClient MyClient = new HttpClient { BaseAddress = new Uri(q.BaseUri) }; switch (q.Activity) { case LinkAction.CreateBase: // create base note LinkCreateModel inputModel = new LinkCreateModel(); inputModel.linkedfile = notefilename; inputModel.Secret = q.Secret; inputModel.header = (db.NoteHeader.SingleOrDefault(p => p.LinkGuid == q.LinkGuid)).CloneForLink(); inputModel.content = (db.NoteContent.SingleOrDefault(p => p.NoteHeaderId == inputModel.header.Id)).CloneForLink(); try { inputModel.tags = Tags.CloneForLink(await db.Tags.Where(p => p.NoteFileId == notefile.Id && p.NoteHeaderId == inputModel.header.Id) .ToListAsync()); } catch { inputModel.tags = null; } inputModel.header.Id = 0; HttpResponseMessage resp; try { resp = MyClient.PostAsync("api/ApiLink", new ObjectContent(typeof(LinkCreateModel), inputModel, new JsonMediaTypeFormatter())) .GetAwaiter().GetResult(); } catch (Exception ex) { return ex.Message; } string result = await resp.Content.ReadAsStringAsync(); LinkLog ll = new LinkLog() { EventType = "SendCreateNote", EventTime = DateTime.UtcNow, Event = result }; db.LinkLog.Add(ll); if (result == "Ok") db.LinkQueue.Remove(q); await db.SaveChangesAsync(); return result; case LinkAction.CreateResponse: // create response note LinkCreateRModel inputModel2 = new LinkCreateRModel(); inputModel2.linkedfile = notefilename; inputModel2.Secret = q.Secret; inputModel2.header = (await db.NoteHeader.SingleAsync(p => p.LinkGuid == q.LinkGuid)).CloneForLinkR(); inputModel2.content = (await db.NoteContent.SingleAsync(p => p.NoteHeaderId == inputModel2.header.Id)).CloneForLink(); try { inputModel2.tags = Tags.CloneForLink(await db.Tags.Where(p => p.NoteFileId == notefile.Id && p.NoteHeaderId == inputModel2.header.Id) .ToListAsync()); } catch { inputModel2.tags = null; } NoteHeader basehead = await NoteDataManager.GetBaseNoteHeader(db, inputModel2.header.Id); inputModel2.baseGuid = basehead.LinkGuid; inputModel2.header.Id = 0; HttpResponseMessage resp2; try { resp2 = MyClient.PostAsync("api/ApiLinkR", new ObjectContent(typeof(LinkCreateRModel), inputModel2, new JsonMediaTypeFormatter())) .GetAwaiter().GetResult(); } catch (Exception ex) { return ex.Message; } string result2 = resp2.Content.ReadAsStringAsync().GetAwaiter().GetResult(); LinkLog ll2 = new LinkLog() { EventType = "SendRespNote", EventTime = DateTime.UtcNow, Event = result2 }; db.LinkLog.Add(ll2); if (result2 == "Ok") db.LinkQueue.Remove(q); await db.SaveChangesAsync(); return result2; case LinkAction.Edit: LinkCreateEModel model = new LinkCreateEModel() { tags = string.Empty, linkedfile = notefilename, myGuid = q.LinkGuid, Secret = q.Secret }; model.header = (await db.NoteHeader.SingleAsync(p => p.LinkGuid == q.LinkGuid)).CloneForLinkR(); model.content = (await db.NoteContent.SingleAsync(p => p.NoteHeaderId == model.header.Id)).CloneForLink(); List<Tags> myTags; try { myTags = await db.Tags.Where(p => p.NoteFileId == notefile.Id && p.NoteHeaderId == model.header.Id).ToListAsync(); if (myTags == null || myTags.Count < 1) { model.tags = string.Empty; } else { foreach (var tag in myTags) { model.tags += tag.Tag + " "; } model.tags.TrimEnd(' '); } } catch { model.tags = string.Empty; } model.header.Id = 0; HttpResponseMessage resp3; try { resp3 = MyClient.PutAsync("api/ApiLink", new ObjectContent(typeof(LinkCreateEModel), model, new JsonMediaTypeFormatter())) .GetAwaiter().GetResult(); } catch (Exception ex) { return ex.Message; } string result3 = resp3.Content.ReadAsStringAsync().GetAwaiter().GetResult(); LinkLog ll3 = new LinkLog() { EventType = "EditNote", EventTime = DateTime.UtcNow, Event = result3 }; db.LinkLog.Add(ll3); if (result3 == "Ok") db.LinkQueue.Remove(q); await db.SaveChangesAsync(); return result3; default: return "Bad Link Activity Request"; } }