本文整理汇总了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
}));
}
示例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));
}
示例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;
}
示例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);
}
示例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));
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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));
}
示例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));
}
示例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));
}