コード例 #1
0
 public int UpdateAssetType(xPlug.BusinessObject.AssetType assetType)
 {
     try
     {
         //Re-Map Object to Entity Object
         var myEntityObj = AssetTypeMapper.Map <xPlug.BusinessObject.AssetType, AssetType>(assetType);
         if (myEntityObj == null)
         {
             return(12);
         }
         using (var db = new ExpenseManagerDBEntities())
         {
             if (db.AssetTypes.Any())
             {
                 if (db.AssetTypes.Count(m => m.Name == myEntityObj.Name && m.AssetTypeId != myEntityObj.AssetTypeId) > 0)
                 {
                     return(-3);
                 }
             }
             db.AssetTypes.Attach(myEntityObj);
             db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified);
             db.SaveChanges();
             return(1);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
コード例 #2
0
 public List <xPlug.BusinessObject.AssetType> GetAssetTypesByAssetCategoryId(Int32 assetCategoryId)
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObjList         = db.AssetTypes.ToList().FindAll(m => m.AssetCategoryId == assetCategoryId);
             var myBusinessObjList = new List <xPlug.BusinessObject.AssetType>();
             if (myObjList == null)
             {
                 return(myBusinessObjList);
             }
             //Re-Map each Entity Object to Business Object
             foreach (var item in myObjList)
             {
                 var myBusinessObj = AssetTypeMapper.Map <AssetType, xPlug.BusinessObject.AssetType>(item);
                 if (myBusinessObj == null)
                 {
                     continue;
                 }
                 myBusinessObjList.Add(myBusinessObj);
             }
             return(myBusinessObjList);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(new List <xPlug.BusinessObject.AssetType>());
     }
 }
コード例 #3
0
        public int AddAssetType(xPlug.BusinessObject.AssetType assetType)
        {
            try
            {
                //Re-Map Object to Entity Object
                var myEntityObj = AssetTypeMapper.Map <xPlug.BusinessObject.AssetType, AssetType>(assetType);
                if (myEntityObj == null)
                {
                    return(-2);
                }
                using (var db = new ExpenseManagerDBEntities())
                {
                    if (db.AssetTypes.Any())
                    {
                        if (db.AssetTypes.Count(m => m.Name == myEntityObj.Name) > 0)
                        {
                            return(-3);
                        }
                    }

                    db.AddToAssetTypes(myEntityObj);
                    db.SaveChanges();
                    assetType.AssetTypeId = myEntityObj.AssetTypeId;
                    return(assetType.AssetTypeId);
                }
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
コード例 #4
0
 public xPlug.BusinessObject.AssetType GetAssetType(int assetTypeId)
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObj = db.AssetTypes.SingleOrDefault(s => s.AssetTypeId == assetTypeId);
             if (myObj == null)
             {
                 return(new xPlug.BusinessObject.AssetType());
             }
             //Re-Map Entity Object to Business Object
             var myBusinessObj = AssetTypeMapper.Map <AssetType, xPlug.BusinessObject.AssetType>(myObj);
             if (myBusinessObj == null)
             {
                 return(new xPlug.BusinessObject.AssetType());
             }
             { return(myBusinessObj); }
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(new xPlug.BusinessObject.AssetType());
     }
 }
コード例 #5
0
 public List <BusinessObject.AssetType> GetAllAssetTypes()
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObjList         = db.AssetTypes.ToList();
             var myBusinessObjList = new List <BusinessObject.AssetType>();
             if (!myObjList.Any())
             {
                 return(myBusinessObjList);
             }
             //Re-Map each Entity Object to Business Object
             foreach (var item in myObjList)
             {
                 var myBusinessObj = AssetTypeMapper.Map <AssetType, BusinessObject.AssetType>(item);
                 if (myBusinessObj == null)
                 {
                     continue;
                 }
                 myBusinessObjList.Add(myBusinessObj);
             }
             return(myBusinessObjList.OrderBy(m => m.Name).ToList());
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(new List <xPlug.BusinessObject.AssetType>());
     }
 }
コード例 #6
0
        public async Task <int> CreateAsync(CreateAssetTypeDto request)
        {
            AssetType assetType = AssetTypeMapper.Map(request) ?? throw new ArgumentNullException(nameof(request));

            if (await _assetTypeRepository.AnyAsync(x => x.Name.Equals(request.Name)))
            {
                throw new ValidationException($"{request.Name} already exist.");
            }
            _assetTypeRepository.Add(assetType);

            return(await _unitOfWork.SaveChangesAsync());
        }
コード例 #7
0
 public ActionResult GetAll()
 {
     try
     {
         var assetTypeList = _faciTechDbContext
                             .AssetType
                             .Select(e => _assetTypeMapper.Map(e));
         return(Ok(assetTypeList));
     }
     catch (Exception ex)
     {
         return(new UnknownErrorResult(ex, base._errorEnabled));
     }
 }
コード例 #8
0
        public BusinessObject.AssetType GetLastInsertedAssetTypeByAssetCategory(int assetCategoryId)
        {
            try
            {
                using (var db = new ExpenseManagerDBEntities())
                {
                    var myObjList         = db.AssetTypes.Where(m => m.AssetCategoryId == assetCategoryId).ToList();
                    var myBusinessObjList = new List <BusinessObject.AssetType>();
                    if (!myObjList.Any())
                    {
                        return(new BusinessObject.AssetType());
                    }
                    //Re-Map each Entity Object to Business Object
                    foreach (var item in myObjList)
                    {
                        var myBusinessObj = AssetTypeMapper.Map <AssetType, BusinessObject.AssetType>(item);

                        if (myBusinessObj == null)
                        {
                            continue;
                        }

                        myBusinessObjList.Add(myBusinessObj);
                    }

                    if (!myBusinessObjList.Any())
                    {
                        return(new BusinessObject.AssetType());
                    }
                    var obj = myBusinessObjList.OrderByDescending(m => m.Code).ElementAt(0);
                    return(obj);
                }
            }
            catch (Exception ex)
            {
                ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
                return(new BusinessObject.AssetType());
            }
        }