Ejemplo n.º 1
0
        public async Task <int> Update(ViewAsset viewAsset, IFormFileCollection formFileCollection)
        {
            DaoAssign    daoAssign    = new DaoAssign(context);
            DaoDeptAsset daoDeptAsset = new DaoDeptAsset(context);
            Asset        asset        = new Asset();
            Assign       assign       = new Assign();
            DeptAsset    deptAsset    = new DeptAsset();

            asset     = viewAsset.asset;
            assign    = viewAsset.assign;
            deptAsset = viewAsset.DeptAsset;
            List <EavAttributeValue> lsAttributeValue = new List <EavAttributeValue>();

            lsAttributeValue = viewAsset.EavAttributeValue;
            var checkCode = this.CheckUniqueAssetCode(asset.AssetCode, asset.AssetId);

            if (checkCode)
            {
                var assetDB = context.Asset.Where(p => p.AssetId.Equals(asset.AssetId)).FirstOrDefault();
                if (assetDB != null)
                {
                    asset.CopyPropertiesTo <Asset>(assetDB);
                    assetDB.UpdatedAt = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
                    context.Asset.Update(assetDB);
                    if (deptAsset != null && !string.IsNullOrEmpty(deptAsset.DeptId))
                    {
                        deptAsset.AssetId = asset.AssetId;
                        daoDeptAsset.Add(deptAsset);
                    }
                    if (assign != null && !string.IsNullOrEmpty(assign.ReceiverBy))
                    {
                        assign.AssetId = asset.AssetId;
                        daoAssign.AssignAsset(assign);
                    }

                    foreach (EavAttributeValue item in lsAttributeValue)
                    {
                        if (!string.IsNullOrEmpty(item.Guid))
                        {
                            context.EavAttributeValue.Update(item);
                        }
                        else
                        {
                            item.Guid           = Guid.NewGuid().ToString().ToUpper();
                            item.CategoryId     = asset.AssetId;
                            item.AttributeGroup = !string.IsNullOrEmpty(item.Value) ? EnumEAV.EAV_Type.AssetAttribute.ToString() : EnumEAV.EAV_Type.AssetCategory.ToString();
                            context.EavAttributeValue.Add(item);
                        }
                    }
                    List <Image> lsAssetImage = new List <Image>();
                    lsAssetImage = new Function().DangTaiHinhAnh(formFileCollection, asset.AssetId);
                    context.Image.AddRange(lsAssetImage);
                }
            }
            return(await context.SaveChangesAsync());
        }
Ejemplo n.º 2
0
        public int UpdateAsset(Asset asset, Assign assign)
        {
            DaoAssign daoAssign = new DaoAssign(context);
            var       entity    = context.Asset.AsNoTracking().Where(p => p.AssetId.Equals(asset.AssetId)).FirstOrDefault();
            bool      checkCode = this.CheckUniqueAssetCode(asset.AssetCode, asset.AssetId);

            if (checkCode)
            {
                asset.UpdatedAt = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
                context.Asset.Update(asset);
                if (assign != null)
                {
                    assign.AssetId = asset.AssetId;
                    daoAssign.AssignAsset(assign);
                }
            }
            return(context.SaveChanges());
        }
Ejemplo n.º 3
0
        public int AddAsset(Asset asset, Assign assign)
        {
            string    a         = EnumEAV.EAV_Type.Area.ToString();
            DaoAssign daoAssign = new DaoAssign(context);

            asset.AssetId = this.GenerateAssetID();
            var checkCode = this.CheckUniqueAssetCode(asset.AssetCode, asset.AssetId);

            if (checkCode)
            {
                asset.CreatedAt = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
                asset.UpdatedAt = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
                context.Asset.Add(asset);
                if (assign != null)
                {
                    assign.AssetId = asset.AssetId;
                    daoAssign.AssignAsset(assign);
                }
            }
            return(context.SaveChanges());
        }
Ejemplo n.º 4
0
        public async Task <int> Add(ViewAsset viewAsset, IFormFileCollection formFileCollection)
        {
            DaoAssign    daoAssign    = new DaoAssign(context);
            DaoDeptAsset daoDeptAsset = new DaoDeptAsset(context);
            Asset        asset        = new Asset();
            Assign       assign       = new Assign();
            DeptAsset    deptAsset    = new DeptAsset();

            asset     = viewAsset.asset;
            assign    = viewAsset.assign;
            deptAsset = viewAsset.DeptAsset;
            List <EavAttributeValue> lsAttributeValue = new List <EavAttributeValue>();

            lsAttributeValue = viewAsset.EavAttributeValue;
            asset.AssetId    = this.GenerateAssetID();
            if (string.IsNullOrEmpty(asset.AssetCode))
            {
                asset.AssetCode = asset.AssetId;
            }
            var checkCode = this.CheckUniqueAssetCode(asset.AssetCode, asset.AssetId);

            if (checkCode)
            {
                asset.CreatedAt = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
                asset.UpdatedAt = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
                context.Asset.Add(asset);

                if (asset.CategoryID != null)
                {
                    EavAttributeValue cate = new EavAttributeValue();
                    cate.Guid           = Guid.NewGuid().ToString().ToUpper();
                    cate.CategoryId     = asset.AssetId;
                    cate.EavId          = asset.CategoryID;
                    cate.AttributeGroup = EnumEAV.EAV_Type.AssetCategory.ToString();
                    context.EavAttributeValue.Add(cate);
                }
                if (asset.LocationID != null)
                {
                    EavAttributeValue cate = new EavAttributeValue();
                    cate.Guid           = Guid.NewGuid().ToString().ToUpper();
                    cate.CategoryId     = asset.AssetId;
                    cate.EavId          = asset.LocationID;
                    cate.AttributeGroup = EnumEAV.EAV_Type.AssetLocation.ToString();
                    context.EavAttributeValue.Add(cate);
                }
                if (assign != null && !string.IsNullOrEmpty(assign.ReceiverBy))
                {
                    assign.AssetId = asset.AssetId;
                    daoAssign.AssignAsset(assign);
                }
                if (deptAsset != null && !string.IsNullOrEmpty(deptAsset.DeptId))
                {
                    deptAsset.AssetId = asset.AssetId;
                    daoDeptAsset.Add(deptAsset);
                }
                if (lsAttributeValue != null)
                {
                    foreach (EavAttributeValue item in lsAttributeValue)
                    {
                        item.Guid           = Guid.NewGuid().ToString().ToUpper();
                        item.CategoryId     = asset.AssetId;
                        item.AttributeGroup = EnumEAV.EAV_Type.AssetAttribute.ToString();
                        context.EavAttributeValue.Add(item);
                    }
                }
                List <Image> lsAssetImage = new List <Image>();
                lsAssetImage = new Function().DangTaiHinhAnh(formFileCollection, asset.AssetId);
                context.Image.AddRange(lsAssetImage);
            }
            return(await context.SaveChangesAsync());
        }