public JsonResult AssignLocation() { string json = Request.InputStream.ReadToEnd(); AssetLocationModel inputData = JsonConvert.DeserializeObject <AssetLocationModel>(json); bool success = false; string error = ""; AssetManagementEntities entities = new AssetManagementEntities(); try { //haetaan ensin paikan id-numero koodin perusteella int locationId = (from l in entities.Location where l.Code == inputData.LocationCode select l.LocationId).FirstOrDefault(); //haetaan ensin laitteen id-numero koodin perusteella int assetId = (from a in entities.Asset where a.Code == inputData.AssetCode select a.AssetId).FirstOrDefault(); if ((locationId > 0) && (assetId > 0)) { //tallennetaan uusi rivi aikaleiman kanssa kantaan AssetLocations newEntry = new AssetLocations(); newEntry.LocationId = locationId; newEntry.AssetId = assetId; newEntry.LastSeen = DateTime.Now; entities.AssetLocations.Add(newEntry); entities.SaveChanges(); success = true; } } catch (Exception ex) { error = ex.GetType().Name + ": " + ex.Message; } finally { entities.Dispose(); } //palautetaan JSON-muotoinen tulos kutsujalle var result = new { success = success, error = error }; return(Json(result)); }
public JsonResult AssignLocation() //JsonResult=palauttaa Jsonia, AssignLocation=rutiinin nimi { string json = Request.InputStream.ReadToEnd(); //laajennusmetodi, WebUtilities.cs luokkaan AssignLocationModel inputData = JsonConvert.DeserializeObject <AssignLocationModel>(json); bool success = false; //oletetaan ettei onnistu string error = ""; Asset2Entities entities = new Asset2Entities(); try { // haetaan ensin paikan id-numero koodin perusteella int locationId = (from l in entities.AssetLocation where l.Code == inputData.LocationCode select l.Id).FirstOrDefault(); // haetaan laitteen id-numero koodin perusteella int assetId = (from a in entities.Assets where a.Code == inputData.AssetCode select a.Id).FirstOrDefault(); if ((locationId > 0) && (assetId > 0)) { // UUDEN RIVIN TALLENTAMINEN aikaleiman kanssa TIETOKANTAAN AssetLocations newEntry = new AssetLocations(); newEntry.LocationId = locationId; newEntry.AssetId = assetId; newEntry.LastSeen = DateTime.Now; entities.AssetLocations.Add(newEntry); entities.SaveChanges(); success = true; //muutetaan success=true } } catch (Exception ex) { error = ex.GetType().Name + ": " + ex.Message; } finally { entities.Dispose(); } // palautetaan JSON-muotoinen tulos kutsujalle var result = new { success = success, error = error }; return(Json(result)); }
private static void SetAssetPath(IAgateTest t, AssetLocations assets) { var assemblyName = t.GetType().GetTypeInfo().Assembly.GetName().Name; assets.Path = assemblyName + "/Assets"; }