public BusinessObject.StaffUser GetStaffUserByMembershipId(int membershipIdId)
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObj = db.StaffUsers.Where(s => s.PortalUserId == membershipIdId).ToList();
             if (!myObj.Any())
             {
                 return(new BusinessObject.StaffUser());
             }
             //Re-Map Entity Object to Business Object
             var myBusinessObj = StaffUserMapper.Map <StaffUser, BusinessObject.StaffUser>(myObj.ElementAt(0));
             if (myBusinessObj == null)
             {
                 return(new BusinessObject.StaffUser());
             }
             { return(myBusinessObj); }
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(new BusinessObject.StaffUser());
     }
 }
 public List <xPlug.BusinessObject.StaffUser> GetStaffUsersByBeneficiaryId(Int32 beneficiaryId)
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObjList         = db.StaffUsers.ToList().FindAll(m => m.BeneficiaryId == beneficiaryId);
             var myBusinessObjList = new List <xPlug.BusinessObject.StaffUser>();
             if (myObjList == null)
             {
                 return(myBusinessObjList);
             }
             //Re-Map each Entity Object to Business Object
             foreach (var item in myObjList)
             {
                 var myBusinessObj = StaffUserMapper.Map <StaffUser, xPlug.BusinessObject.StaffUser>(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.StaffUser>());
     }
 }
 public xPlug.BusinessObject.StaffUser GetStaffUser(int staffUserId)
 {
     try
     {
         using (var db = new ExpenseManagerDBEntities())
         {
             var myObj = db.StaffUsers.SingleOrDefault(s => s.StaffUserId == staffUserId);
             if (myObj == null)
             {
                 return(new xPlug.BusinessObject.StaffUser());
             }
             //Re-Map Entity Object to Business Object
             var myBusinessObj = StaffUserMapper.Map <StaffUser, xPlug.BusinessObject.StaffUser>(myObj);
             if (myBusinessObj == null)
             {
                 return(new xPlug.BusinessObject.StaffUser());
             }
             { return(myBusinessObj); }
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(new xPlug.BusinessObject.StaffUser());
     }
 }
 public bool UpdateStaffUser(xPlug.BusinessObject.StaffUser staffUser)
 {
     try
     {
         //Re-Map Object to Entity Object
         var myEntityObj = StaffUserMapper.Map <BusinessObject.StaffUser, StaffUser>(staffUser);
         if (myEntityObj == null)
         {
             return(false);
         }
         using (var db = new ExpenseManagerDBEntities())
         {
             db.StaffUsers.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);
     }
 }
 public int AddStaffUser(xPlug.BusinessObject.StaffUser staffUser)
 {
     try
     {
         //Re-Map Object to Entity Object
         var myEntityObj = StaffUserMapper.Map <xPlug.BusinessObject.StaffUser, StaffUser>(staffUser);
         if (myEntityObj == null)
         {
             return(-2);
         }
         using (var db = new ExpenseManagerDBEntities())
         {
             db.AddToStaffUsers(myEntityObj);
             db.SaveChanges();
             staffUser.StaffUserId = myEntityObj.StaffUserId;
             return(staffUser.StaffUserId);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }