public IActionResult Get(int id) { var item = DbContext.Items.FirstOrDefault(i => i.Id == id); if (item != null) { return(new JsonResult(TinyMapper.Map <ItemViewModel>(item), DefaultJsonSettings)); } else { return(NotFound(new { Error = $"Item ID {id} has not been found." })); } }
static void Main(string[] args) { TinyMapper.Bind <SourceClass, TargetClass>(); var source = new SourceClass { FirstName = "Luke", LastName = "Chen" }; var result = TinyMapper.Map <TargetClass>(source); Console.WriteLine(result.FullName); Console.ReadLine(); }
/// <summary> /// 映射对象 /// </summary> /// <typeparam name="Target"></typeparam> /// <param name="source"></param> /// <returns></returns> public static Target MapTo <Target>(this object source) { Target target = default(Target); try { target = TinyMapper.Map <Target>(source); } catch (Exception) { } return(target); }
public IActionResult Get(string id) { var contractor = DbContext.Contractor.Where(c => c.ID == id).FirstOrDefault(); if (contractor == null) { return(NotFound(new { Error = String.Format("Contractor ID {0} not found", id) })); } else { return(new JsonResult(TinyMapper.Map <ContractorViewModel>(contractor), DefaultJsonSettings)); } }
public async Task <Reseller> Add(NewResellerModel model) { Validate(model); var reseller = TinyMapper.Map <Reseller>(model); reseller.Id = Guid.NewGuid(); reseller.CPF = model.CPF.ApplyCPFFormat(); reseller.Password = Hasher.CreatePasswordHash(model.Email, model.Password); await _resellerRepository.Add(reseller); _logger.LogDebug($"[ResellerService/Add] {model.Email} adicionado"); return(reseller); }
public HttpResponseMessage GetChoreUsers(int ChoreListId) { try { TinyMapper.Bind <List <ChoreUser>, List <_ChoreUser> >(); var ChoreUsers = TinyMapper.Map <List <_ChoreUser> >(ChoreRepository.GetChoreUsers(ChoreListId)); return(OKResponse(ChoreUsers)); } catch (Exception ex) { return(ErrorResponse(ex)); } }
public IActionResult Add([FromBody] ClothesViewModel cvm) { if (cvm != null) { var item = TinyMapper.Map <ClothesItem>(cvm); item.CreatedDate = DateTime.Now; item.LastModifiedDate = DateTime.Now; DbContext.ClothesItems.Add(item); DbContext.SaveChanges(); return(new JsonResult(TinyMapper.Map <ClothesItem>(item), DefaultJsonSettings)); } return(new StatusCodeResult(500)); }
public async Task <IActionResult> Register([FromBody] RegisterViewModel model) { if (!ModelState.IsValid) { throw new ArgumentNullException(nameof(model)); } var user = await _authService.Register(model.Email, model.UserName, model.Password); var result = TinyMapper.Map <UserDto>(user); return(new JsonResult(result)); }
public void AddCompetitor(CompetitorModel competitor) { if (ValidateCompetitorExists(competitor)) { TinyMapper.Bind <CompetitorModel, CompetitorEntity>(); var competitorEntity = TinyMapper.Map <CompetitorEntity>(competitor); _repository.Insert(competitorEntity); } else { throw new Exception("Competitor already exists!"); } }
public IActionResult Get(int id) { var item = DbContext.Items.Where(i => i.Id == id).FirstOrDefault(); if (item != null) { return(new JsonResult(TinyMapper.Map <ItemViewModel>(item), DefaultJsonSettings)); } else { return(NotFound(new { Error = String.Format("Item ID {0} has not been found", id) })); } }
public async Task <Product> GetProduct(Guid id) { var product = await _productsContext.Products.FirstOrDefaultAsync(p => p.Id == id); // throw not found if (product == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } // return mapped product return(TinyMapper.Map <Product>(product)); }
public void DataPoint_to_Weather() { // prepare DSModel.DataPoint src = PrepareForecastData().Daily.Data[0]; // execute Weather output = TinyMapper.Map <Weather>(src); // assert output.Visibility.ShouldBe(src.Visibility); output.Temperature.ShouldNotBeNull(); output.Temperature.Daily.ShouldBe(src.Temperature.Daily); output.Temperature.DewPoint.ShouldBe(src.Temperature.DewPoint); }
public void Map_ConvertibleType_Success() { TinyMapper.Bind <Source1, Target1>(); var source = new Source1 { FirstName = "First", LastName = "Last" }; var result = TinyMapper.Map <Target1>(source); Assert.Equal(string.Format("{0} {1}", source.FirstName, source.LastName), result.FullName); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { var concreteValue = (PurchaseOrder)value; return(new PurchaseOrderModel { Id = concreteValue.Id, Date = concreteValue.Date, Value = concreteValue.Value, Status = concreteValue.Status.SwitchStatusToDescription(), Reseller = TinyMapper.Map <ResellerModel>(concreteValue.Reseller) }); }
public List <NistSalModel> GetInformationTypes(int assessmentId) { TinyMapper.Bind <NIST_SAL_INFO_TYPES, NistSalModel>(); CreateInitialList(assessmentId); using (CSET_Context db = new CSET_Context()) { List <NistSalModel> rlist = new List <NistSalModel>(); foreach (NIST_SAL_INFO_TYPES t in db.NIST_SAL_INFO_TYPES.Where(x => x.Assessment_Id == assessmentId)) { rlist.Add(TinyMapper.Map <NistSalModel>(t)); } return(rlist); } }
public Finding GetFinding(int finding_id) { Finding webF; if (finding_id != 0) { FINDING f = assessmentContext.FINDING .Where(x => x.Finding_Id == finding_id) .Include(fc => fc.FINDING_CONTACT) .FirstOrDefault(); var q = assessmentContext.ANSWER.Where(x => x.Answer_Id == this.answer_id).FirstOrDefault(); webF = TinyMapper.Map <Finding>(f); webF.Question_Id = q != null ? q.Question_Or_Requirement_Id : 0; webF.Finding_Contacts = new List <FindingContact>(); foreach (var contact in assessmentContext.ASSESSMENT_CONTACTS.Where(x => x.Assessment_Id == assessment_id)) { FindingContact webContact = TinyMapper.Map <FindingContact>(contact); webContact.Name = contact.PrimaryEmail + " -- " + contact.FirstName + " " + contact.LastName; webContact.Selected = (f.FINDING_CONTACT.Where(x => x.Assessment_Contact_Id == contact.Assessment_Contact_Id).FirstOrDefault() != null); webF.Finding_Contacts.Add(webContact); } } else { var q = assessmentContext.ANSWER.Where(x => x.Answer_Id == this.answer_id).FirstOrDefault(); FINDING f = new FINDING() { Answer_Id = answer_id }; assessmentContext.FINDING.Add(f); assessmentContext.SaveChanges(); webF = TinyMapper.Map <Finding>(f); webF.Finding_Contacts = new List <FindingContact>(); foreach (var contact in assessmentContext.ASSESSMENT_CONTACTS.Where(x => x.Assessment_Id == assessment_id)) { FindingContact webContact = TinyMapper.Map <FindingContact>(contact); webContact.Finding_Id = f.Finding_Id; webContact.Name = contact.PrimaryEmail + " -- " + contact.FirstName + " " + contact.LastName; webContact.Selected = false; webF.Finding_Contacts.Add(webContact); } } return(webF); }
public Sals SaveNistQuestions(int assessmentid, NistQuestionsAnswers answer) { using (CSET_Context db = new CSET_Context()) { var dbAnswer = db.NIST_SAL_QUESTION_ANSWERS.Where(x => x.Assessment_Id == assessmentid && x.Question_Id == answer.Question_Id).FirstOrDefault(); if (dbAnswer == null) { throw new ApplicationException(String.Format("Question {0} could not be found for assessment {1}!", answer.Question_Number, assessmentid)); } TinyMapper.Map <NistQuestionsAnswers, NIST_SAL_QUESTION_ANSWERS>(answer, dbAnswer); db.SaveChanges(); return(CalculateOveralls(assessmentid, db)); } }
public async Task <ProjectDto> AddProject(SaveProjectDto projectDto) { TinyMapper.Bind <SaveProjectDto, Project>(); TinyMapper.Bind <Project, ProjectDto>(); var project = TinyMapper.Map <Project>(projectDto); project.Created = UnixTimeStamp(); await _projectRepository.AddAsync(project); await _projectRepository.CommitAsync(); return(TinyMapper.Map <ProjectDto>(project)); }
public void Test() { TinyMapper.Bind <Source, Target>(config => config.Bind(from => @from.Campaign, typeof(Campaign1))); var source = new Source { Campaign = new Campaign1 { Value = 1 } }; var result = TinyMapper.Map <Target>(source); }
public List <Importance> GetImportance() { int assessmentId = Auth.AssessmentForUser(); List <Importance> rlist = new List <Importance>(); using (CSET_Context context = new CSET_Context()) { foreach (IMPORTANCE import in context.IMPORTANCE) { rlist.Add(TinyMapper.Map <Importance>(import)); } } return(rlist); }
public void DataPointList_to_WeatherGroup() { // prepare List <OWModel.DataPointDSL> src = PrepareForecastData().Daily; // execute WeatherGroup output = new WeatherGroup(TinyMapper.Map <List <Weather> >(src)); // assert output.Count.ShouldBe(src.Count); output.ShouldAllBe(dp => dp.Visibility > 0); output.ShouldAllBe(dp => dp.Temperature != null); output.ShouldAllBe(dp => dp.Temperature.Daily != 0.0f); output.ShouldAllBe(dp => !string.IsNullOrWhiteSpace(dp.Summary)); }
public void Map_NullCollection_Success() { var source = new Source2 { Int = 1 }; TinyMapper.Bind <Source2, Target2>(); var actual = TinyMapper.Map <Target2>(source); Assert.Equal(source.Ints, actual.Ints); Assert.Equal(source.Int, actual.Int); }
public void TinyMap_null_map() { MyTaBleEntity myTaBleEntity = null; var myTinyMapDto = new MyTinyMapDto { MyProperty = "1", MyProperty2 = 1 }; TinyMapper.Map(myTinyMapDto, myTaBleEntity); _testOutputHelper.WriteLine("ok"); }
public IActionResult Add([FromBody] ItemViewModel ivm) { if (ivm != null) { var item = TinyMapper.Map <Item>(ivm); item.CreatedDate = DateTime.Now; item.LastModifiedDate = DateTime.Now; item.UserId = DbContext.Users.Where(u => u.UserName == "Admin").FirstOrDefault().Id; DbContext.Items.Add(item); DbContext.SaveChanges(); return(new JsonResult(TinyMapper.Map <ItemViewModel>(item), DefaultJsonSettings)); } return(new StatusCodeResult(500)); }
public async Task <IActionResult> Add([FromBody] ItemViewModel ivm) { if (ivm != null) { var item = TinyMapper.Map <Item>(ivm); item.CreatedDate = item.LastModifiedDate = DateTime.Now; item.UserId = await GetCurrentUserId(); DbContext.Items.Add(item); DbContext.SaveChanges(); return(new JsonResult(TinyMapper.Map <ItemViewModel>(item), DefaultJsonSettings)); } return(new StatusCodeResult(500)); }
public IActionResult Post([FromBody] UserModel user) { var existingUser = _userRepository.GetUserByEmail(user.Email); if (existingUser != null) { return(BadRequest()); } ; var userId = _userRepository.AddUser(TinyMapper.Map <User>(user)); return(Created(string.Format("/api/users/{0}", userId), user)); }
public async Task <L7ConversationDetailDTO> GetByIdAsync(Guid id) { var l7ConversationEntity = await this._repositoryReaderAsync.GetByIdAsync(id).ConfigureAwait(false); if (l7ConversationEntity == null) { return(null); } var l7ConversationDetailDto = TinyMapper.Map <L7ConversationDetailDTO>(l7ConversationEntity); l7ConversationDetailDto.Pdus = l7ConversationEntity.Pdus.Select(TinyMapper.Map <L7PduDTO>); return(l7ConversationDetailDto); }
public IActionResult Update(int id, [FromBody] ClothesViewModel cvm) { var item = DbContext.ClothesItems.Where(i => i.Id == id).FirstOrDefault(); if (item != null && cvm != null) { item.Description = cvm.Description; item.Shop = cvm.Shop; item.LastModifiedDate = DateTime.Now; DbContext.SaveChanges(); return(new JsonResult(TinyMapper.Map <ClothesViewModel>(item), DefaultJsonSettings)); } return(NotFound(new { Error = string.Format("Item Id {0} has not been found", id) })); }
public _AccountType(AccountType Value) { try { TinyMapper.Bind <AccountType, _AccountType>(); TinyMapper.Map <AccountType, _AccountType>(Value, this); this.BasePricePerMonth = decimal.Round(BasePricePerMonth, 2); } catch (Exception ex) { throw Utility.ThrowException(ex); } }
private IList <SysMenuViewModel> GetTreeMenu(Expression <Func <SysMenu, bool> > where) { var reslut = new List <SysMenuViewModel>(); var children = Get(where).OrderBy(m => m.SortIndex).ToList(); foreach (var child in children) { var tmp = new SysMenuViewModel(); tmp = TinyMapper.Map(child, tmp); tmp.Children = GetTreeMenu(m => m.ParentId == tmp.Id && m.Activable); reslut.Add(tmp); } return(reslut); }