예제 #1
0
 public IDataResult <List <DepartmentDTO> > GetAll()
 {
     return(new DataResult <List <DepartmentDTO> >()
     {
         Data = Repo.GetAll().Result.Select(e => Mapper.Map(e)).ToList(),
         Message = ResponseMessageType.None,
         ResponseStatusType = ResponseStatusType.Successed
     });
 }
예제 #2
0
 public List <xPlug.BusinessObject.Department> GetDepartments()
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObjList         = db.Departments.ToList();
             var myBusinessObjList = new List <xPlug.BusinessObject.Department>();
             if (myObjList == null)
             {
                 return(myBusinessObjList);
             }
             //Re-Map each Entity Object to Business Object
             foreach (var item in myObjList)
             {
                 var myBusinessObj = DepartmentMapper.Map <Department, xPlug.BusinessObject.Department>(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.Department>());
     }
 }
예제 #3
0
 public xPlug.BusinessObject.Department GetDepartment(int departmentId)
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObj = db.Departments.SingleOrDefault(s => s.DepartmentId == departmentId);
             if (myObj == null)
             {
                 return(new xPlug.BusinessObject.Department());
             }
             //Re-Map Entity Object to Business Object
             var myBusinessObj = DepartmentMapper.Map <Department, xPlug.BusinessObject.Department>(myObj);
             if (myBusinessObj == null)
             {
                 return(new xPlug.BusinessObject.Department());
             }
             { return(myBusinessObj); }
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(new xPlug.BusinessObject.Department());
     }
 }
 public List <BusinessObject.Unit> GetActiveFilteredOrderedUnits()
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObjList         = db.Units.Where(m => m.DepartmentId != 8).ToList();
             var myBusinessObjList = new List <BusinessObject.Unit>();
             if (!myObjList.Any())
             {
                 return(myBusinessObjList);
             }
             //Re-Map each Entity Object to Business Object
             foreach (var item in myObjList)
             {
                 var myBusinessObj = DepartmentMapper.Map <Unit, BusinessObject.Unit>(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 <BusinessObject.Unit>());
     }
 }
 public int UpdateDepartmentCheckDuplicate(BusinessObject.Department department)
 {
     try
     {
         //Re-Map Object to Entity Object
         var myEntityObj = DepartmentMapper.Map <BusinessObject.Department, Department>(department);
         if (myEntityObj == null)
         {
             return(-2);
         }
         using (var db = new ExpenseManagerDBEntities())
         {
             if (db.Departments.Count(m => m.Name.ToLower().Replace(" ", string.Empty) == department.Name.ToLower().Replace(" ", string.Empty) && m.DepartmentId != department.DepartmentId) > 0)
             {
                 return(-3);
             }
             db.Departments.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);
     }
 }
 public IEnumerable <Department> GetDataUsingDataContract()
 {
     using (var c = new SqlConnection(Constants.CS))
     {
         var m = new DepartmentMapper();
         c.Open();
         using (var cmd = c.CreateCommand())
         {
             cmd.CommandText = "GetDepartments";
             cmd.CommandType = System.Data.CommandType.StoredProcedure;
             using (var r = cmd.ExecuteReader())
             {
                 return(m.Map(r));
             }
         };
     }
 }
예제 #7
0
 public bool UpdateDepartment(xPlug.BusinessObject.Department department)
 {
     try
     {
         //Re-Map Object to Entity Object
         var myEntityObj = DepartmentMapper.Map <xPlug.BusinessObject.Department, Department>(department);
         if (myEntityObj == null)
         {
             return(false);
         }
         using (var db = new ExpenseManagerDBEntities())
         {
             db.Departments.Attach(myEntityObj);
             db.ObjectStateManager.ChangeObjectState(myEntityObj, EntityState.Modified);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(false);
     }
 }
예제 #8
0
 public int AddDepartment(xPlug.BusinessObject.Department department)
 {
     try
     {
         //Re-Map Object to Entity Object
         var myEntityObj = DepartmentMapper.Map <xPlug.BusinessObject.Department, Department>(department);
         if (myEntityObj == null)
         {
             return(-2);
         }
         using (var db = new ExpenseManagerDBEntities())
         {
             db.AddToDepartments(myEntityObj);
             db.SaveChanges();
             department.DepartmentId = myEntityObj.DepartmentId;
             return(department.DepartmentId);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
예제 #9
0
        public async Task <DepartmentDto> Get(int id)
        {
            var department = await this.unitOfWork.DepartmentRepository.Get(id);

            return(DepartmentMapper.Map(department));
        }