当前位置: 首页>>代码示例>>C#>>正文


C# List.ToDataSourceResult方法代码示例

本文整理汇总了C#中List.ToDataSourceResult方法的典型用法代码示例。如果您正苦于以下问题:C# List.ToDataSourceResult方法的具体用法?C# List.ToDataSourceResult怎么用?C# List.ToDataSourceResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在List的用法示例。


在下文中一共展示了List.ToDataSourceResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Products_Create

 public ActionResult Products_Create([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<ProductViewModel> products)
 {
     // Will keep the inserted entitites here. Used to return the result later.
     var entities = new List<Product>();
     if (ModelState.IsValid)
     {
         using (var northwind = new NorthwindEntities())
         {
             foreach (var product in products)
             {
                 // Create a new Product entity and set its properties from the posted ProductViewModel
                 var entity = new Product
                 {
                     ProductName = product.ProductName,
                     UnitsInStock = product.UnitsInStock
                 };
                 // Add the entity
                 northwind.Products.Add(entity);
                 // Store the entity for later use
                 entities.Add(entity);
             }
             // Insert the entities in the database
             northwind.SaveChanges();
         }
     }
     // Return the inserted entities. The grid needs the generated ProductID. Also return any validation errors.
     return Json(entities.ToDataSourceResult(request, ModelState, product => new ProductViewModel
     {
         ProductID = product.ProductID,
         ProductName = product.ProductName,
         UnitsInStock = product.UnitsInStock
     }));
 }
开发者ID:turtlechalk,项目名称:ui-for-aspnet-mvc-examples,代码行数:33,代码来源:HomeController.cs

示例2: FDP_Create

        public ActionResult FDP_Create([DataSourceRequest] DataSourceRequest request, FDPViewModel fdpViewModel , int? adminUnitID)
        {
            var result = new List<FDPViewModel>();

            if (fdpViewModel != null && ModelState.IsValid && adminUnitID.HasValue)
            {
                try
                {
                    //foreach (var viewModel in fdpViewModel)
                    //{

                    if (CheckIfDFPExists((int)adminUnitID, fdpViewModel.Name))
                        {
                            fdpViewModel.AdminUnitID = adminUnitID.Value;
                            var fdp = FDPViewModelBinder.BindFDP(fdpViewModel);
                            _fdpService.AddFDP(fdp);
                            //result.Add(fdpViewModel);
                        }
                   // }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Errors", @"Error: FDP not registered. All fields need to be filled.");
                }
            }
            return Json(result.ToDataSourceResult(request, ModelState));
        }
开发者ID:FishAbe,项目名称:cats,代码行数:27,代码来源:FDPController.cs

示例3: CreatePet

        public ActionResult CreatePet([DataSourceRequest]DataSourceRequest request, IEnumerable<AdministrationPetsViewModel> models)
        {
            var result = new List<AdministrationPetsViewModel>();
            if (this.ModelState.IsValid && models != null)
            {
                foreach (var model in models)
                {
                    var owner = this.users.GetByUsername(model.Owner).FirstOrDefault();
                    var breed = this.breeds.GetById(model.BreedId).FirstOrDefault();
                    var location = this.locations.GetById(model.LocationId).FirstOrDefault();
                    var status = this.petStatuses.GetById(model.PetStatusId).FirstOrDefault();
                    if (owner != null && breed != null && location != null && status != null)
                    {
                        var newPet = new Pet { Name = model.Name, Description = model.Description, Breed = breed, Owner = owner, Location = location, PetStatus = status, ImageUrl = model.ImageUrl, PetGender = model.PetGenderType };
                        this.pets.Add(newPet);
                        model.CreatedOn = newPet.CreatedOn;
                        model.Id = newPet.Id;
                        result.Add(model);
                    }
                }

                return this.Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
            }

            return null;
        }
开发者ID:KonstantinAdamu,项目名称:PetRescue,代码行数:26,代码来源:PetsAdministrationController.cs

示例4: List_Read

 public JsonResult List_Read(DataSourceRequest request)
 {
     var items = _activityBusinessLogic.GetAllEntities().ToArray();//.Select(x => new ActivityModel
     //{
     //    Id = x.Id,
     //    ActivityDate = x.CreateDate,
     //    UserName = x.Author.Name,
     //    Type = x.Type.Name,
     //    UserAgent = x.UserAgent,
     //    //Tags = x.GetAllTags(),
     //}).ToList();
     items.FirstOrDefault();
     var act = new List<ActivityModel>();
     foreach (var activity in items)
     {
         act.Add(new ActivityModel
         {
             Tags = activity.GetAllTags(),
             Id = activity.Id,
             UserAgent = activity.UserAgent,
             ActivityDate = activity.CreateDate,
             UserName = activity.Author.Name,
             //Type = activity.Type.Name
         });
     }
     DataSourceResult result = act.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
开发者ID:MaximGomon,项目名称:SCA,代码行数:28,代码来源:ContactActivityController.cs

示例5: Section_Create

        public ActionResult Section_Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Section> sections)
        {
            var results = new List<Section>();

            if (sections != null && ModelState.IsValid)
            {
                foreach (var section in sections)
                {
                    var addedSection = sectionDataHandler.AddSection(section);
                    if (addedSection != null)
                    {
                        ViewBag.Message = "Record saved";
                        ViewBag.ErrorFound = false;

                        section.SectionID = addedSection.SectionID;
                    }
                    else
                    {
                        ViewBag.Message = "Failed to save record";
                        ViewBag.ErrorFound = true;

                    }

                    results.Add(section);
                }
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
开发者ID:tzaman536,项目名称:TestRepository,代码行数:29,代码来源:ReferenceDataController.cs

示例6: CreateRating

        public ActionResult CreateRating([DataSourceRequest]DataSourceRequest request, IEnumerable<AdministrationRatingsViewModel> models)
        {
            var result = new List<AdministrationRatingsViewModel>();
            if (this.ModelState.IsValid && models != null)
            {
                foreach (var model in models)
                {
                    var ratingUser = this.users.GetByUsername(model.UserName).FirstOrDefault();
                    var petToUpdate = this.pets.GetByIntId(model.PetId).FirstOrDefault();
                    if (ratingUser != null && petToUpdate != null)
                    {
                        var newRating = new Rating { RatingValue = model.RatingValue, PetId = model.PetId, Author = ratingUser };
                        this.ratings.Add(newRating);
                        petToUpdate.CurrentRating = petToUpdate.Ratings.Average(r => r.RatingValue);
                        this.pets.Update(petToUpdate);
                        model.CreatedOn = newRating.CreatedOn;
                        model.Id = newRating.Id;
                        result.Add(model);
                    }
                }

                return this.Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
            }

            return null;
        }
开发者ID:KonstantinAdamu,项目名称:PetRescue,代码行数:26,代码来源:RatingsAdministrationController.cs

示例7: Pie_Read

        public ActionResult Pie_Read([DataSourceRequest] DataSourceRequest request)
        {
            var Dessert = db.Dessert.Where(x => x.DessertKind == "Pie" && x.IsOnSale);
            List<AddDessertViewModel> PieDessert = new List<AddDessertViewModel>();
                foreach (var item in Dessert)
                {
                    PieDessert.Add(AddModel(item));
                }

            return Json(PieDessert.ToDataSourceResult(request));
        }
开发者ID:hgkiller01,项目名称:VincentDraw2,代码行数:11,代码来源:ProductViewController.cs

示例8: GetCompanies

 public JsonResult GetCompanies(DataSourceRequest request)
 {
     var items = _companyBusinessLogic.GetAllEntities().ToList();
     var models = new List<CompanyModel>();
     foreach (var company in items)
     {
         models.Add(company.ConvertToCompanyModel());
     }
     var result = models.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
开发者ID:MaximGomon,项目名称:SCA,代码行数:11,代码来源:CompaniesController.cs

示例9: List_Read

 public JsonResult List_Read(DataSourceRequest request, Guid id)
 {
     var items = _siteBusinessLogic.GetAllEntities().Where(x => x.Owner.Id == id);//.Select(x => ConvertToSiteModel(x));
     var models = new List<SiteModel>();
     foreach (var clientSite in items)
     {
         models.Add(clientSite.ConvertToSiteModel());
     }
     DataSourceResult result = models.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
开发者ID:MaximGomon,项目名称:SCA,代码行数:11,代码来源:SiteController.cs

示例10: GetCompanySites

 public JsonResult GetCompanySites(DataSourceRequest request, Guid id)
 {
     var items = _companyBusinessLogic.GetAllEntities().Where(x => x.Id == id).SelectMany(x => x.Sites).ToList();
     var models = new List<SiteModel>();
     foreach (var site in items)
     {
         models.Add(site.ConvertToSiteModel());
     }
     var result = models.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
开发者ID:MaximGomon,项目名称:SCA,代码行数:11,代码来源:CompaniesController.cs

示例11: List_Read

 public JsonResult List_Read(DataSourceRequest request)
 {
     var items = _leadTypeBusinessLogic.GetAllEntities();//.Select(x => ConvertToSiteModel(x));
     var models = new List<LeadTypeModel>();
     foreach (var clientSite in items)
     {
         //models.Add(ConvertToLeadModel(clientSite));
     }
     DataSourceResult result = models.ToDataSourceResult(request);
     return Json(result, JsonRequestBehavior.AllowGet);
 }
开发者ID:MaximGomon,项目名称:SCA,代码行数:11,代码来源:LeadTypeController.cs

示例12: Log_Read

 public async Task<JsonResult> Log_Read([DataSourceRequest]DataSourceRequest request, string userID = "")
 {
     List<SlotTransactionModel> allSlotTransaction = new List<SlotTransactionModel>();
     if (string.IsNullOrWhiteSpace(userID))
     {
        
         using (var client = new HttpClient())
         {
             string url = System.Configuration.ConfigurationManager.AppSettings["SmartParkingAPI"];
             client.BaseAddress = new Uri(url);
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             HttpResponseMessage response = await client.GetAsync("api/SlotTransaction/GetSlotTransaction");
             if (response.IsSuccessStatusCode)
             {
                 allSlotTransaction = await response.Content.ReadAsAsync<List<SlotTransactionModel>>();
             }
         }
         DataSourceResult result = allSlotTransaction.ToDataSourceResult(request);
         return Json(result);
     }
     else
     {
         int UserID = int.Parse(userID);                 
         using (var client = new HttpClient())
         {
             string url = System.Configuration.ConfigurationManager.AppSettings["SmartParkingAPI"];
             client.BaseAddress = new Uri(url);
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             HttpResponseMessage response = await client.GetAsync("api/SlotTransaction/GetSlotTransactionAsUser?userId=" + UserID);
             if (response.IsSuccessStatusCode)
             {
                 allSlotTransaction = await response.Content.ReadAsAsync<List<SlotTransactionModel>>();
             }
         }
         DataSourceResult result = allSlotTransaction.ToDataSourceResult(request);
         return Json(result);
     }
     
 }
开发者ID:neovasolutions,项目名称:MSTeam_SmartParkingSystem_Phase3,代码行数:41,代码来源:UserLogController.cs

示例13: CreateRate

        public ActionResult CreateRate([DataSourceRequest] DataSourceRequest request,
            [Bind(Prefix = "models")]IEnumerable<ProviderRate> products)
        {
            var results = new List<ProviderRate>();

            if (products != null && ModelState.IsValid)
            {
                results.AddRange(products);
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
开发者ID:pravinady,项目名称:SquareCare,代码行数:12,代码来源:ProviderController.cs

示例14: Editing_Create

        public ActionResult Editing_Create([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
        {
            var results = new List<ProductViewModel>();

            if (product != null && ModelState.IsValid)
            {
                SessionProductRepository.Insert(product);
                results.Add(product);
            }

            return Json(results.ToDataSourceResult(request, ModelState));
        }
开发者ID:pgdesjardins,项目名称:LabourScheduling,代码行数:12,代码来源:EditingController.cs

示例15: Create

 public ActionResult Create([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<LessonTypeGrid> lessons)
 {
     var results = new List<LessonTypeGrid>();
     if (lessons != null)
     {
         foreach (var lesson in lessons)
         {
             store.Create(lesson);
             results.Add(lesson);
         }
     }
     return Json(results.ToDataSourceResult(request));
 }
开发者ID:KarenManukyan,项目名称:ScheduleOfFaculty,代码行数:13,代码来源:LessonTypeController.cs


注:本文中的List.ToDataSourceResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。