public ActionResult Query(AppDTO param, PageParam pageParam) { List <AppDTO> list = new List <AppDTO>(); _typeAdapter.Adapt(_appService.Query(param, pageParam).ToList(), list); return(Json(new { total = pageParam.TotalRecordCount, rows = list })); }
public IList <BannerViewModel> GetAll(int pageNumber, int limit) { var results = _bannerRepository.Query(a => a.Id > 0).ToList(); IList <BannerViewModel> resultMapped = _typeAdapter.Adapt <List <BannerEntity>, List <BannerViewModel> >(results); return(resultMapped); }
/// <summary> /// 根据登录名取学院 /// </summary> /// <param name="loginName"></param> /// <returns></returns> public IEnumerable <SchoolView> GetSchoolByLoginName(string loginName) { //取学院 var schools = new BooksellerAppl().GetSchoolByLoginName(loginName); return(_adapter.Adapt <SchoolView>(schools)); }
public IEnumerable <DataSignView> GetDataSign() { var result = new DataSignAppl().GetAll(); result = result.OrderByDescending(t => t.Name); return(_adapter.Adapt <DataSignView>(result)); }
public ActionResult <List <PersonDTO> > Get() { var persons = _personService.GetPersons(); // PersonDTO is a Data Transfer Object of Person var personsDTO = _adapter.Adapt <List <PersonDTO> >(persons); return(Ok(personsDTO)); }
public IEnumerable <PressView> GetPresses() { var presses = _pressRepo.GetAll(); presses = presses.OrderBy(t => t.Name); return(_adapter.Adapt <PressView>(presses)); }
/// <summary> /// 根据登录名取学院 /// </summary> /// <param name="loginName"></param> /// <returns></returns> public IEnumerable <SchoolView> GetSchoolByloginName(string loginName) { //系统用户 var user = new TbmisUserAppl(loginName).GetUser(); //取当前登录用户的学院 var schoolAppl = new SchoolAppl(); var school = schoolAppl.GetSchoolOfUser(loginName); return(_adapter.Adapt <SchoolView>(school)); }
public IEnumerable <SchoolView> GetSchoolWithNotApproval(string loginName) { //系统用户 var user = new TbmisUserAppl(loginName).GetUser(); //最大学期 var term = new TermAppl().GetMaxTerm().YearTerm; IList <School> schools = new List <School>(); ////如果是教务处或教材科,取全部学院 //if (user.IsInRole("教务处")) //{ // var school = _declRepo.Find(t => // t.Term == term && // t.ApprovalState == ApprovalState.教务处审核中 // ).Select(t => // t.TeachingTask.Department.School // ).Distinct(); // schools = school.ToList(); //} //else if (user.IsInRole("教材科")) //{ // var school = _declRepo.Find(t => // t.Term == term && // t.ApprovalState == ApprovalState.教材科审核中 // ).Select(t => // t.TeachingTask.Department.School // ).Distinct(); // schools = school.ToList(); //} ////如果是学院院长,返回所属学院 //else if (user.IsInRole("学院院长") || user.IsInRole("教研室主任")) //{ // var school = new School { SchoolId = (Guid)user.SchoolId, Name = user.SchoolName }; // schools.Add(school); //} if (schools.Count > 0) { return(_adapter.Adapt <SchoolView>(schools)); } else { IEnumerable <SchoolView> school = new List <SchoolView> { new SchoolView { SchoolId = string.Empty, Name = "没有需要审核的学院" } }; return(school); } }
public void EnumerableProductToListProductDTOAdapter() { //Arrange var software = new Software("the title", "The description", "AB001"); software.ChangeUnitPrice(10); software.IncrementStock(10); software.GenerateNewIdentity(); var products = new List <Software>() { software }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var productsDTO = adapter.Adapt <IEnumerable <Product>, List <ProductDTO> >(products); //Assert Assert.AreEqual(products[0].Id, productsDTO[0].Id); Assert.AreEqual(products[0].Title, productsDTO[0].Title); Assert.AreEqual(products[0].Description, productsDTO[0].Description); Assert.AreEqual(products[0].AmountInStock, productsDTO[0].AmountInStock); Assert.AreEqual(products[0].UnitPrice, productsDTO[0].UnitPrice); }
public void EnumerableBookToListBookDTOAdapter() { //Arrange var book = new Book("the title", "The description", "Krasis Press", "ABD12"); book.ChangeUnitPrice(10); book.IncrementStock(10); book.GenerateNewIdentity(); var books = new List <Book>() { book }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var booksDTO = adapter.Adapt <IEnumerable <Book>, List <BookDTO> >(books); //Assert Assert.Equal(books[0].Id, booksDTO[0].Id); Assert.Equal(books[0].Title, booksDTO[0].Title); Assert.Equal(books[0].Description, booksDTO[0].Description); Assert.Equal(books[0].AmountInStock, booksDTO[0].AmountInStock); Assert.Equal(books[0].UnitPrice, booksDTO[0].UnitPrice); Assert.Equal(books[0].ISBN, booksDTO[0].ISBN); Assert.Equal(books[0].Publisher, booksDTO[0].Publisher); }
public void AdaptBankAccountToBankAccountDTO() { //Arrange var country = new Country("Spain", "es-ES"); country.GenerateNewIdentity(); var customer = CustomerFactory.CreateCustomer("jhon", "el rojo", "+3441", "company", country, new Address("", "", "", "")); customer.GenerateNewIdentity(); BankAccount account = new BankAccount(); account.GenerateNewIdentity(); account.BankAccountNumber = new BankAccountNumber("4444", "5555", "3333333333", "02"); account.SetCustomerOwnerOfThisBankAccount(customer); account.DepositMoney(1000, "reason"); account.Lock(); //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var bankAccountDTO = adapter.Adapt <BankAccount, BankAccountDTO>(account); //Assert Assert.Equal(account.Id, bankAccountDTO.Id); Assert.Equal(account.Iban, bankAccountDTO.BankAccountNumber); Assert.Equal(account.Balance, bankAccountDTO.Balance); Assert.Equal(account.Customer.FirstName, bankAccountDTO.CustomerFirstName); Assert.Equal(account.Customer.LastName, bankAccountDTO.CustomerLastName); Assert.Equal(account.Locked, bankAccountDTO.Locked); }
public void EnumerableSoftwareToListSoftwareDTOAdapter() { //Arrange var software = new Software("the title", "The description", "AB001"); software.ChangeUnitPrice(10); software.IncrementStock(10); software.GenerateNewIdentity(); var softwares = new List <Software>() { software }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var softwaresDTO = adapter.Adapt <IEnumerable <Software>, List <SoftwareDTO> >(softwares); //Assert Assert.Equal(softwares[0].Id, softwaresDTO[0].Id); Assert.Equal(softwares[0].Title, softwaresDTO[0].Title); Assert.Equal(softwares[0].Description, softwaresDTO[0].Description); Assert.Equal(softwares[0].AmountInStock, softwaresDTO[0].AmountInStock); Assert.Equal(softwares[0].UnitPrice, softwaresDTO[0].UnitPrice); Assert.Equal(softwares[0].LicenseCode, softwaresDTO[0].LicenseCode); }
public IHttpActionResult TicketMessage() { if (User.IsInRole(RoleConfig.AppRole)) { var app = _appService.Query(new AppDTO { Name = User.Identity.Name }, null).FirstOrDefault(); return(Json( new { AppID = app.ID, AppName = app.Name, RedirectUri = app.ReturnUrl })); } var userData = _userService.GetUserByName(User.Identity.Name); var result = _typeAdapter.Adapt <UserDTO>(userData); return(Json(new { UserID = result.UserID, UserName = result.Name, Mobile = result.Mobile, Email = result.Email })); }
public void CountryEnumerableToCountryDTOList() { //Arrange var country = new Country("Spain", "es-ES"); country.GenerateNewIdentity(); IEnumerable <Country> countries = new List <Country>() { country }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var dtos = adapter.Adapt <IEnumerable <Country>, List <CountryDTO> >(countries); //Assert Assert.NotNull(dtos); Assert.True(dtos.Any()); Assert.True(dtos.Count == 1); var dto = dtos[0]; Assert.Equal(country.Id, dto.Id); Assert.Equal(country.CountryName, dto.CountryName); Assert.Equal(country.CountryISOCode, dto.CountryISOCode); }
public void AdaptEnumerableBankActivityToListBankActivityDTO() { //Arrange BankAccountActivity activity = new BankAccountActivity(); activity.GenerateNewIdentity(); activity.Date = DateTime.Now; activity.Amount = 1000; activity.ActivityDescription = "transfer..."; IEnumerable <BankAccountActivity> activities = new List <BankAccountActivity>() { activity }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var activitiesDTO = adapter.Adapt <IEnumerable <BankAccountActivity>, List <BankActivityDTO> >(activities); //Assert Assert.NotNull(activitiesDTO); Assert.True(activitiesDTO.Count() == 1); Assert.Equal(activity.Date, activitiesDTO[0].Date); Assert.Equal(activity.Amount, activitiesDTO[0].Amount); Assert.Equal(activity.ActivityDescription, activitiesDTO[0].ActivityDescription); }
public void BlogEnumerableToBlogDTOList() { //Arrange var blog = BlogFactory.CreateBlog("Name", "Url", 0); IEnumerable <Blog> blogs = new List <Blog>() { blog }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var dtos = adapter.Adapt <IEnumerable <Blog>, List <BlogDTO> >(blogs); //Assert Assert.NotNull(dtos); Assert.True(dtos.Any()); Assert.True(dtos.Count == 1); var dto = dtos[0]; Assert.Equal(blog.BlogId, dto.BlogId); Assert.Equal(blog.Name, dto.Name); Assert.Equal(blog.Url, dto.Url); Assert.Equal(blog.Rating, dto.Rating); }
public virtual TUiDto Add(TBareDto dto) { try { // convert to a domain entity TDomainEntity domainEntity = _bareDtoToDomainAdapter.Adapt(dto); // add to database Tuple <bool, TDomainEntity> addResult = _domainService.Add(domainEntity); return(addResult.Item1 ? _domainToUiDtoAdapter.Adapt(addResult.Item2) : null); } catch (Exception ex) { _logger.LogError(ex, Literals.p_ErrorAddingDtoOfTypeX.ParseParameter(typeof(TBareDto).Name)); throw; } }
public IEnumerable <SchoolView> GetSchoolByLoginName(string loginName) { var school = new SchoolAppl().GetSchoolOfUser(loginName); school = school.OrderBy <School, string>(t => t.Name); return(_adapter.Adapt <SchoolView>(school)); }
public void OrderToOrderDTOAdapter() { //Arrange Customer customer = new Customer(); customer.GenerateNewIdentity(); customer.FirstName = "Unai"; customer.LastName = "Zorrilla"; Product product = new Software("the product title", "the product description", "license code"); product.GenerateNewIdentity(); Order order = new Order(); order.GenerateNewIdentity(); order.OrderDate = DateTime.Now; order.ShippingInformation = new ShippingInfo("shippingName", "shippingAddress", "shippingCity", "shippingZipCode"); order.SetTheCustomerForThisOrder(customer); var orderLine = order.AddNewOrderLine(product.Id, 10, 10, 0.5M); orderLine.SetProduct(product); //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var orderDTO = adapter.Adapt <Order, OrderDTO>(order); //Assert Assert.AreEqual(orderDTO.Id, order.Id); Assert.AreEqual(orderDTO.OrderDate, order.OrderDate); Assert.AreEqual(orderDTO.DeliveryDate, order.DeliveryDate); Assert.AreEqual(orderDTO.ShippingAddress, order.ShippingInformation.ShippingAddress); Assert.AreEqual(orderDTO.ShippingCity, order.ShippingInformation.ShippingCity); Assert.AreEqual(orderDTO.ShippingName, order.ShippingInformation.ShippingName); Assert.AreEqual(orderDTO.ShippingZipCode, order.ShippingInformation.ShippingZipCode); Assert.AreEqual(orderDTO.CustomerFullName, order.Customer.FullName); Assert.AreEqual(orderDTO.CustomerId, order.Customer.Id); Assert.AreEqual(orderDTO.OrderNumber, string.Format("{0}/{1}-{2}", order.OrderDate.Year, order.OrderDate.Month, order.SequenceNumberOrder)); Assert.IsNotNull(orderDTO.OrderLines); Assert.IsTrue(orderDTO.OrderLines.Any()); Assert.AreEqual(orderDTO.OrderLines[0].Id, orderLine.Id); Assert.AreEqual(orderDTO.OrderLines[0].Amount, orderLine.Amount); Assert.AreEqual(orderDTO.OrderLines[0].Discount, orderLine.Discount * 100); Assert.AreEqual(orderDTO.OrderLines[0].UnitPrice, orderLine.UnitPrice); Assert.AreEqual(orderDTO.OrderLines[0].TotalLine, orderLine.TotalLine); Assert.AreEqual(orderDTO.OrderLines[0].ProductId, product.Id); Assert.AreEqual(orderDTO.OrderLines[0].ProductTitle, product.Title); }
// GET: Admin/Account public ActionResult Index() { var userDTO = _typeAdapter.Adapt <UserDTO>(_userService.GetUserByName(UserName)); if (userDTO.Name.Equals("admin")) { userDTO.IsAdmin = true; } return(View(userDTO)); }
public Report CreateReport( string name, ReportTemplate template, User user, Organization organization, OrganizationRole organizationRole, Dictionary <string, dynamic> parameters) { Report report = _typeAdapter.Adapt <ReportTemplate, Report>(template); report.SetCreationOptions(parameters); var properties = new (string, object)[]
public IEnumerable <BooksellerView> GetBooksellerWithNotApproval(string loginName) { //系统用户 var user = new TbmisUserAppl(loginName).GetUser(); IList <Bookseller> booksellers = new List <Bookseller>(); //如果是教务处或教材科,取全部学院 if (user.IsInRole("教务处")) { var bookseller = _repo.Find(t => t.ApprovalState == ApprovalState.教务处审核中 ).SelectMany(t => t.Subscriptions ).Select(t => t.Bookseller ).Distinct(); booksellers = bookseller.ToList(); } else if (user.IsInRole("教材科")) { var bookseller = _repo.Find(t => t.ApprovalState == ApprovalState.教材科审核中 ).SelectMany(t => t.Subscriptions ).Select(t => t.Bookseller ).Distinct(); booksellers = bookseller.ToList(); } if (booksellers.Count == 0) { var bookseller = new Bookseller { ID = Guid.Empty, Name = "没有需要审核的书商" }; booksellers.Add(bookseller); } return(_adapter.Adapt <BooksellerView>(booksellers)); }
/// <summary> /// 根据班级Id,教材Id,取领用人名单 /// </summary> /// <param name="classId"></param> /// <param name="textbookId"></param> /// <returns></returns> public IEnumerable <StudentForRecipientsView> GetRecipientsByTextbookId(string classId, string textbookId) { var cId = classId.ConvertToGuid(); var tId = textbookId.ConvertToGuid(); var recipients = _studentReleaseRecordRepo.Find(s => s.Class_Id == cId && s.Textbook_Id == tId) .Select(s => new StudentForRecipientsView { StudentId = s.Student_Id.ToString(), StudentNum = s.StudentNum, StudentName = s.StudentName }); return(_typeAdapter.Adapt <StudentForRecipientsView>(recipients)); }
public ResponseView Import(IEnumerable <CasMapperView> casMappers) { var repo = ServiceLocator.Current.GetInstance <ICasMapperRepository>(); var result = new ResponseView(); try { var models = _adapter.Adapt <CasMapper>(casMappers); foreach (var item in models) { repo.Add(item); } repo.Context.Commit(); return(result); } catch (Exception e) { result.Fault(); return(result); } }
public IEnumerable <SubscriptionForFeedbackView> GetSubscriptionWithNotFeedback(string term, string loginName) { //取当前用户的书商ID //var id = new TbmisUserAppl(loginName).GetUser().SchoolId; var id = "60D6E947-EC9C-4A0A-AEA6-26673C046B3C".ConvertToGuid(); //学期 var yearTerm = new SchoolYearTerm(term); //var subscriptions = _subscriptionRepo.Find(t => // t.SchoolYearTerm.Year == yearTerm.Year && //当前学期 // t.SchoolYearTerm.Term == yearTerm.Term && // t.Bookseller_Id == id &&//书商 // t.SubscriptionState == FeedbackState.征订中 // ).Where(t => // !t.Feedback_Id.HasValue // ); //未回告; var subscriptions = GetSubscriptionByState(term, id, FeedbackState.征订中).Where(t => !t.Feedback_Id.HasValue); return(_adapter.Adapt <SubscriptionForFeedbackView>(subscriptions)); }
public async Task <Result <GetProjectResult> > HandleAsync(GetProject queryModel) { var result = await _dbContext.Set <Project>() .SingleOrDefaultAsync(p => p.Id == queryModel.Id); if (result == null) { return(Result.Fail <GetProjectResult>(ErrorMessages.ProjectNotFound)); } return(Result.Ok(_typeAdapter.Adapt <GetProjectResult>(result))); }
public async Task <GetTaskByIdResult> Handle(GetTaskById request, CancellationToken cancellationToken) { var projectTask = await _dbContext.Tasks .AsNoTracking() .SingleOrDefaultAsync(x => x.Id == request.Id, cancellationToken); if (projectTask == null) { throw new NotFoundException("Task does not exist!"); } return(_typeAdapter.Adapt <GetTaskByIdResult>(projectTask)); }
public virtual TRulesDto GetValidationRules() { try { TRuleset ruleset = _domainService.GetValidationRules(); return(_rulesToDtoAdapter.Adapt(ruleset)); } catch (Exception ex) { _logger.LogError(ex, Literals.p_ErrorGettingValidationRules.ParseParameter(typeof(TDomainEntity).Name)); throw; } }
public void CustomerEnumerableToCustomerListDTOListAdapt() { //Arrange var country = new Country("Spain", "es-ES"); country.GenerateNewIdentity(); var address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2"); var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "617404929", "Spirtis", country, address); var picture = new Picture { RawPhoto = new byte[0] { } }; customer.ChangeTheCurrentCredit(1000M); customer.ChangePicture(picture); customer.SetTheCountryForThisCustomer(country); IEnumerable <Customer> customers = new List <Customer>() { customer }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var dtos = adapter.Adapt <IEnumerable <Customer>, List <CustomerListDTO> >(customers); //Assert Assert.IsNotNull(dtos); Assert.IsTrue(dtos.Any()); Assert.IsTrue(dtos.Count == 1); CustomerListDTO dto = dtos[0]; Assert.AreEqual(customer.Id, dto.Id); Assert.AreEqual(customer.FirstName, dto.FirstName); Assert.AreEqual(customer.LastName, dto.LastName); Assert.AreEqual(customer.Company, dto.Company); Assert.AreEqual(customer.Telephone, dto.Telephone); Assert.AreEqual(customer.CreditLimit, dto.CreditLimit); Assert.AreEqual(customer.Address.City, dto.AddressCity); Assert.AreEqual(customer.Address.ZipCode, dto.AddressZipCode); Assert.AreEqual(customer.Address.AddressLine1, dto.AddressAddressLine1); Assert.AreEqual(customer.Address.AddressLine2, dto.AddressAddressLine2); }
public object Adapt(object value, IInterceptor interceptor) { if (value == null) { return(null); } var fromUnderlyingType = Nullable.GetUnderlyingType(this.From); var fromUnderlyingValue = Convert.ChangeType(value, fromUnderlyingType); var toUnderlyingType = Nullable.GetUnderlyingType(this.To); var toUnderlyingValue = _inner.Adapt(fromUnderlyingValue, interceptor); return(Activator.CreateInstance(this.To, toUnderlyingValue)); }