// GET: Depots public ActionResult Index(int?id) { DepotViewModel depotViewModel = new DepotViewModel(); if (id != null) { Depot depot = depotService.GetDepotById(id); depotViewModel = new DepotViewModel() { Id = depot.Id, IsActive = depot.IsActive, Code = depot.Code, GeolocationId = depot.GeolocationId, GeolocationName = depot.Geolocation.Address, DepotTypeId = depot.DepotTypeId, DepotTypeName = depot.DepotType.Name }; } ViewBag.DepotTypeList = new SelectList(genericService.GetList <DepotType>(), "Id", "Name"); ViewBag.GeolocationList = new SelectList(geolocationService.GetGeolocationList().Select(g => new { Id = g.Id, Name = g.Address + ", " + g.City.Name }), "Id", "Name"); return(View(depotViewModel)); }
public void GetList_Returns_ExpectedSlice() { var repoGetList = productRepoCalls["GetList"]; // make sure our full list is what we expect var fullList = productService.GetList(); Assert.AreEqual(100, fullList.Count, "We're expecting 100 elements to exist in our mock"); // weaksauce.. dependent on list setup in SetUp() Assert.AreEqual((repoGetList + 1), productRepoCalls["GetList"], "A single call to the underlying repository is expected"); var partialList = productService.GetList(2, 10); Assert.AreEqual(10, partialList.Count, "Partial list should contain 10 elements."); Assert.AreEqual(10, partialList[0].Id, "First element in the partial list should have Id==10"); Assert.AreEqual(19, partialList[9].Id, "Last element in the partial list should have Id==19"); Assert.AreEqual((repoGetList + 2), productRepoCalls["GetList"], "A second call to the underlying repo is now expected."); partialList = productService.GetList(pageNumber: 1000, pageSize: 10); Assert.AreEqual(0, partialList.Count, "A request outside of the bound of the list should return an empty list."); Assert.AreEqual((repoGetList + 3), productRepoCalls["GetList"], "A third call to the underlying repo is now expected."); partialList = productService.GetList(pageNumber: 10, pageSize: 11); Assert.AreEqual(1, partialList.Count, "A request extending past the bounds of the list should return a list with just the items until the end of the list."); Assert.AreEqual((repoGetList + 4), productRepoCalls["GetList"], "A fourth call to the underlying repo is now expected."); }
// GET: DepotTypes public ActionResult Index(int?id) { DepotType diastolic = new DepotType(); if (id != null) { diastolic = genericService.GetList <DepotType>().Where(o => o.Id == id).FirstOrDefault(); } return(View(diastolic)); }
// GET: Districts public ActionResult Index(int?id) { District district = new District(); if (id != null) { district = districtService.GetDistrictById(id); } ViewBag.ProvinceList = new SelectList(genericService.GetList <Province>(), "Id", "Name"); return(View(district)); }
// GET: Suppliers public ActionResult Index(int?id) { SupplierViewModel supplierViewModel = new SupplierViewModel(); if (id != null) { Supplier supplier = new Supplier(); supplier = genericService.GetList <Supplier>().Where(o => o.Id == id).FirstOrDefault(); supplierViewModel = new SupplierViewModel() { Id = supplier.Id, IsActive = supplier.IsActive, Name = supplier.Name, Address = supplier.Address, Website = supplier.Website, ContactDetails = supplier.ContactDetails }; } return(View(supplierViewModel)); }
// GET: Citys public ActionResult Index(int?id) { CityViewModel cityViewModel = new CityViewModel(); if (id != null) { City city = cityService.GetCityById(id); cityViewModel = new CityViewModel() { Id = city.Id, IsActive = city.IsActive, Name = city.Name, DistrictName = city.District.Name, DistrictId = city.DistrictId.Value }; } ViewBag.DistrictList = new SelectList(genericService.GetList <District>(), "Id", "Name"); return(View(cityViewModel)); }
// GET: Geolocations public ActionResult Index(int?id) { GeolocationViewModel geolocationViewModel = new GeolocationViewModel(); Geolocation geolocation = new Geolocation(); if (id != null) { geolocation = geolocationService.GetGeolocationById(id); geolocationViewModel = new GeolocationViewModel() { Id = geolocation.Id, IsActive = geolocation.IsActive, Address = geolocation.Address + " " + geolocation.City.Name, CityName = geolocation.City.Name }; } ViewBag.CityList = new SelectList(genericService.GetList <City>(), "Id", "Name"); return(View(geolocationViewModel)); }
// GET: GPSDevices public ActionResult Index(int?id) { GPSDeviceViewModel gpsDeviceViewModel = new GPSDeviceViewModel(); if (id != null) { GPSDevice gpsDevice = gpsDeviceService.GetGPSDeviceById(id); gpsDeviceViewModel = new GPSDeviceViewModel() { Id = gpsDevice.Id, IsActive = gpsDevice.IsActive, ModelNumber = gpsDevice.Model, SerialNumber = gpsDevice.SerialNumber, SupplierName = gpsDevice.Supplier.Name }; } ViewBag.SupplierList = new SelectList(genericService.GetList <Supplier>(), "Id", "Name"); return(View(gpsDeviceViewModel)); }
// GET: Organizations public ActionResult Index(int?id) { OrganizationViewModel itemViewModel = new OrganizationViewModel(); if (id != null) { Organization item = new Organization(); item = genericService.GetList <Organization>().Where(o => o.Id == id).FirstOrDefault(); itemViewModel = new OrganizationViewModel() { Id = item.Id, IsActive = item.IsActive, Name = item.Name, Address = item.Address, Website = item.Website, ContactDetails = item.ContactDetails }; } return(View(itemViewModel)); }
// GET: Drivers public ActionResult Index(int?id) { DriverViewModel itemViewModel = new DriverViewModel(); if (id != null) { Driver item = new Driver(); item = genericService.GetList <Driver>().Where(o => o.Id == id).FirstOrDefault(); itemViewModel = new DriverViewModel() { Id = item.Id, IsActive = item.IsActive, Name = item.Name, Address = item.Address, NICNo = item.NICNo, ContactNo = item.ContactNo, DLNo = item.DLNo }; } return(View(itemViewModel)); }
static void Main(string[] args) { Console.WriteLine("Student Details"); //IConfiguration configuration = GetAppSettingsFile(); GenericService service = new GenericService(); List <Student> students = service.GetList <Student>(); foreach (Student student in students) { Console.WriteLine($"Id: {student.Id}, Name: {student.Name}"); } }
// GET: Tanks public ActionResult Index(int?id) { TankViewModel tankViewModel = new TankViewModel(); if (id != null) { Tank tank = tankService.GetTankById(id); tankViewModel = new TankViewModel() { Id = tank.Id, IsActive = tank.IsActive, Code = tank.Code, Volume = tank.Volume, FuelTypeName = tank.FuelType.Name, FuelTypeId = tank.FuelTypeId.Value }; } ViewBag.FuelTypeList = new SelectList(genericService.GetList <FuelType>(), "Id", "Name"); return(View(tankViewModel)); }
public ActionResult GetProducts() { var allProducts = service.GetList(); // turn all of our product data into a structure that we can render // out into json. var vm = new List <object>(); foreach (var p in allProducts) { var node = new { Id = p.Id, Name = p.Name, DefaultLocks = new List <Object>(), Versions = p.Versions.Select(v => new { Id = v.Id, Version = v.Version }) }; // turn our lock-property flag enum property into a list that will make sense // as a json object var allLockProperties = Enum.GetValues(typeof(LockPropertyType)); foreach (LockPropertyType lockType in allLockProperties) { if (lockType == LockPropertyType.None) { continue; } if (p.DefaultLockProperties.HasFlag(lockType)) { node.DefaultLocks.Add( new { Name = Enum.GetName(typeof(LockPropertyType), lockType), Value = lockType }); } } vm.Add(node); } return(Json(vm, JsonRequestBehavior.AllowGet)); }
public ActionResult SaveOrUpdate(DepotTank model) { string newData = string.Empty, oldData = string.Empty; try { int id = model.Id; DepotTank depot = null; DepotTank oldDepotTank = null; if (model.Id == 0) { depot = new DepotTank { DepotId = model.DepotId, TankId = model.TankId, SensorDeviceId = model.SensorDeviceId }; oldDepotTank = new DepotTank(); oldData = new JavaScriptSerializer().Serialize(oldDepotTank); newData = new JavaScriptSerializer().Serialize(depot); } else { depot = genericService.GetList <DepotTank>().Where(o => o.Id == model.Id).FirstOrDefault(); oldDepotTank = genericService.GetList <DepotTank>().Where(o => o.Id == model.Id).FirstOrDefault(); oldData = new JavaScriptSerializer().Serialize(new DepotTank() { Id = oldDepotTank.Id, DepotId = model.DepotId, TankId = model.TankId, SensorDeviceId = model.SensorDeviceId }); depot.DepotId = model.DepotId; depot.TankId = model.TankId; depot.SensorDeviceId = model.SensorDeviceId; newData = new JavaScriptSerializer().Serialize(new DepotTank() { Id = depot.Id, DepotId = depot.DepotId, TankId = depot.TankId, SensorDeviceId = depot.SensorDeviceId }); } genericService.SaveOrUpdate <DepotTank>(depot, depot.Id); //CommonService.SaveDataAudit(new DataAudit() //{ // Entity = "DepotTanks", // NewData = newData, // OldData = oldData, // UpdatedOn = DateTime.Now, // UserId = User.Identity.GetUserId() //}); TempData["Message"] = ResourceData.SaveSuccessMessage; } catch (Exception ex) { TempData["Message"] = string.Format(ResourceData.SaveErrorMessage, ex.InnerException); } return(RedirectToAction("Index", "DepotTank")); }
public ActionResult SaveOrUpdate(VehicleViewModel model) { string newData = string.Empty, oldData = string.Empty; try { int id = model.Id; Vehicle vehicle = null; Vehicle oldVehicle = null; if (model.Id == 0) { vehicle = new Vehicle { VehicleNo = model.VehicleNo, Capacity = model.Capacity, IsActive = true, GPSDeviceId = model.GPSDeviceId }; oldVehicle = new Vehicle(); oldData = new JavaScriptSerializer().Serialize(oldVehicle); newData = new JavaScriptSerializer().Serialize(vehicle); } else { vehicle = genericService.GetList <Vehicle>().Where(o => o.Id == model.Id).FirstOrDefault(); oldVehicle = genericService.GetList <Vehicle>().Where(o => o.Id == model.Id).FirstOrDefault(); oldData = new JavaScriptSerializer().Serialize(new Vehicle() { Id = oldVehicle.Id, Capacity = oldVehicle.Capacity, IsActive = oldVehicle.IsActive, GPSDeviceId = model.GPSDeviceId }); vehicle.VehicleNo = model.VehicleNo; vehicle.Capacity = model.Capacity; vehicle.GPSDeviceId = model.GPSDeviceId; vehicle.IsActive = model.IsActive; newData = new JavaScriptSerializer().Serialize(new Vehicle() { Id = vehicle.Id, VehicleNo = vehicle.VehicleNo, IsActive = vehicle.IsActive }); } genericService.SaveOrUpdate <Vehicle>(vehicle, vehicle.Id); //CommonService.SaveDataAudit(new DataAudit() //{ // Entity = "Vehicles", // NewData = newData, // OldData = oldData, // UpdatedOn = DateTime.Now, // UserId = User.Identity.GetUserId() //}); TempData["Message"] = ResourceData.SaveSuccessMessage; } catch (Exception ex) { TempData["Message"] = string.Format(ResourceData.SaveErrorMessage, ex.InnerException); } return(RedirectToAction("Index", "Vehicle")); }