예제 #1
0
        public JsonResult Location()
        {
            string        json      = Request.InputStream.ReadToEnd();
            LocationModel inputData = JsonConvert.DeserializeObject <LocationModel>(json);
            bool          success   = false;
            string        error     = "";
            AssetEntities entities  = new AssetEntities();

            try
            {
                AssetLocation newEntry = new AssetLocation();
                newEntry.Address = inputData.LocationAddress;
                newEntry.Code    = inputData.LocationCode;
                newEntry.Name    = inputData.LocationName;
                entities.AssetLocations.Add(newEntry);
                entities.SaveChanges();
                success = true;
            }

            catch (Exception ex)
            {
                error = ex.GetType().Name + ": " + ex.Message;
            }
            finally
            {
                entities.Dispose();
            }
            var result = new { success = success, error = error };

            return(Json(result));
        }
예제 #2
0
        public ActionResult List()
        {
            List <AssetinNakymaViewModel> model = new List <AssetinNakymaViewModel>();

            AssetEntities entities = new AssetEntities();

            try
            {
                List <AssetLocation1> assets = entities.AssetLocations1.ToList();

                // muodostetaan näkymämalli tietokannan rivien pohjalta
                CultureInfo fiFi = new CultureInfo("fi-FI");
                foreach (AssetLocation1 asset in assets)
                {
                    AssetinNakymaViewModel view = new AssetinNakymaViewModel();
                    view.Id           = asset.Id;
                    view.LocationCode = asset.AssetLocation.Code;
                    view.LocationName = asset.AssetLocation.Name;
                    view.AssetCode    = asset.Asset.Code;
                    view.AssetName    = asset.Asset.Type + ": " + asset.Asset.Model;
                    view.LastSeen     = asset.LastSeen.Value.ToString(fiFi);

                    model.Add(view);
                }
            }
            finally
            {
                entities.Dispose();
            }

            return(View(model));
        }
예제 #3
0
 public AssetEntity GetAssetById(string assetId)
 {
     return(AssetEntities
            .Include(x => x.StreamingUrl)
            .Include(x => x.AssetMetaDataEntity)
            .FirstOrDefault(x => x.Id.ToString()
                            .Equals(assetId)));
 }
예제 #4
0
 public Task <List <AssetEntity> > SearchForAssets(VideoSearchRequest videoSearchRequest)
 {
     if (videoSearchRequest == null)
     {
         return(AssetEntities
                .Include(x => x.StreamingUrl)
                .Include(x => x.AssetMetaDataEntity).Select(x => x).Take(10)
                .OrderByDescending(x => x.CreatedDate)
                .ToListAsync());
     }
     throw new NotImplementedException();
 }
        public static async Task <AssetEntities> GetAllAssetsAsync(this SquidexAssetClient assetClient, int batchSize = 200)
        {
            var skip     = 0;
            var entities = new AssetEntities();

            do
            {
                var getResult = await assetClient.GetAssetsAsync(skip : skip, top : batchSize);

                entities.Total = getResult.Total;
                entities.Items.AddRange(getResult.Items);

                skip += entities.Items.Count;
            }while (skip < entities.Total);

            return(entities);
        }
        public static async Task <AssetEntities> GetAllAssetsAsync(this SquidexAssetClient assetClient, int batchSize = 200)
        {
            var query = new ODataQuery {
                Top = batchSize, Skip = 0
            };

            var entities = new AssetEntities();

            do
            {
                var getResult = await assetClient.GetAssetsAsync(query);

                entities.Total = getResult.Total;
                entities.Items.AddRange(getResult.Items);

                query.Skip = entities.Items.Count;
            }while (query.Skip < entities.Total);

            return(entities);
        }
예제 #7
0
        public JsonResult AssignLocation()
        {
            string json = Request.InputStream.ReadToEnd();
            AssignLocationModel inputData = JsonConvert.DeserializeObject <AssignLocationModel>(json);

            bool          success  = false;
            string        error    = "";
            AssetEntities entities = new AssetEntities();

            try
            {
                int LocationId = (from l in entities.AssetLocations
                                  where l.Code == inputData.LocationCode
                                  select l.Id).FirstOrDefault();
                int AssetId = (from a in entities.Assets
                               where a.Code == inputData.AssetCode
                               select a.Id).FirstOrDefault();

                if (LocationId > 0 && AssetId > 0)
                {
                    AssetLocation1 newEntry = new AssetLocation1();
                    newEntry.AssetId    = AssetId;
                    newEntry.LocationId = LocationId;
                    newEntry.LastSeen   = DateTime.Now;
                    entities.AssetLocations1.Add(newEntry);
                    entities.SaveChanges();
                    success = true;
                }
            }
            catch (Exception ex)
            {
                error = ex.GetType().Name + ": " + ex.Message;
            }
            finally
            {
                entities.Dispose();
            }
            var result = new { success = success, error = error };

            return(Json(result));
        }
예제 #8
0
        public async Task <AssetEntity> CreateUpdateAssetEntity(MediaAsset mediaAsset)
        {
            var assetEntity = AssetEntity.CreateInstance();

            assetEntity.Id              = Guid.NewGuid();
            assetEntity.FileName        = mediaAsset.FormFile.FileName;
            assetEntity.AssetName       = mediaAsset.AssetName;
            assetEntity.InputAssetName  = mediaAsset.InputAssetName;
            assetEntity.OutputAssetName = mediaAsset.OutputAssetName;
            assetEntity.JobName         = mediaAsset.JobName;
            assetEntity.LocatorName     = mediaAsset.LocatorName;
            assetEntity.StreamingUrl    = mediaAsset.StreamingUrls.Select(x =>
            {
                var url = new StreamingUrl
                {
                    Id = Guid.NewGuid(), AssetEntityId = assetEntity.Id, AssetEntity = assetEntity, Url = x.Url
                };
                return(url);
            }).ToHashSet();
            assetEntity.AssetMetaDataEntity = new AssetMetaDataEntity
            {
                Id            = Guid.NewGuid(),
                AssetEntityId = assetEntity.Id,
                AssetEntity   = assetEntity,
                FirstName     = mediaAsset.AssetMetaData.FirstName,
                LastName      = mediaAsset.AssetMetaData.LastName,
                PhoneNumber   = mediaAsset.AssetMetaData.PhoneNumber,
                Street        = mediaAsset.AssetMetaData.Street,
                ZipCode       = mediaAsset.AssetMetaData.ZipCode,
                City          = mediaAsset.AssetMetaData.City,
                State         = mediaAsset.AssetMetaData.State,
                Date          = mediaAsset.AssetMetaData.Date,
                Time          = mediaAsset.AssetMetaData.Time
            };
            await AssetEntities.AddAsync(assetEntity);

            await SaveChangesAsync();

            return(assetEntity);
        }
예제 #9
0
 public async Task <AssetEntity> GetAssetsByName(string filename)
 {
     return(await AssetEntities
            .Include(x => x.StreamingUrl)
            .FirstOrDefaultAsync(x => x.FileName == filename));
 }