예제 #1
0
        private UserModel MapToUserModel(User userDB, AccessControlSystemEntities context)
        {
            UserModel userModel = new UserModel();

            userModel.Id        = userDB.Id;
            userModel.Name      = userDB.Name;
            userModel.Role      = userDB.Role;
            userModel.Password  = userDB.Password;
            userModel.CompanyId = userDB.CompanyId == null ? 0: (int)userDB.CompanyId;
            return(userModel);
        }
예제 #2
0
        public MessageFromCompanyModel GetMessageFromCompanyById(int messageId, int CompanyId)
        {
            AccessControlSystemEntities context = new AccessControlSystemEntities();

            try
            {
                MessageFromCompany message = context.MessageFromCompanies.Where(x => x.CompanyId == CompanyId && x.Id == messageId).FirstOrDefault();
                return(MapToMemberMessageFromCompanyModel(message, context));
            }
            catch (Exception e)
            {
            }
            return(null);
        }
        public void AddNewEntryToDataBase(int memberId)
        {
            AccessControlSystemEntities context = new AccessControlSystemEntities();

            try
            {
                Entry entry = new Entry();
                entry.MemberId = memberId;
                entry.Time     = DateTime.Now;
                context.Entries.Add(entry);
                context.SaveChanges();
            }
            catch (Exception e)
            {
            }
        }
        public MemberModel CheckMemberByCardNumber(string CardNumber)
        {
            AccessControlSystemEntities context = new AccessControlSystemEntities();

            try
            {
                Member member = context.Members.Where(x => x.CardNumber == CardNumber).FirstOrDefault();
                if (member != null)
                {
                    return(MapToMemberModel(member, context));
                }
            }
            catch (Exception e)
            {
            }
            return(null);
        }
        public static List <CompanyModel> GetCompanies()
        {
            AccessControlSystemEntities context = new AccessControlSystemEntities();

            try
            {
                List <Company>      companies    = context.Companies.ToList();
                List <CompanyModel> memberModels = new List <CompanyModel>();
                foreach (Company item in companies)
                {
                    memberModels.Add(MapToCompanyModel(item, context));
                }
                return(memberModels);
            }
            catch (Exception e)
            {
            }
            return(null);
        }
예제 #6
0
        public List <UserModel> GetUsers()
        {
            List <UserModel> users = new List <UserModel>();

            try
            {
                AccessControlSystemEntities context = new AccessControlSystemEntities();
                List <User> usersDb = context.Users.ToList();

                foreach (var item in usersDb)
                {
                    users.Add(MapToUserModel(item, context));
                }
            }
            catch (Exception e)
            {
            }
            return(users);
        }
예제 #7
0
        public void AddNewMember(MemberModel model)
        {
            AccessControlSystemEntities context = new AccessControlSystemEntities();

            try
            {
                Member memberDB = new Member();
                memberDB.CardNumber = model.CardNumber;
                memberDB.FirstName  = model.FirstName;
                memberDB.LastName   = model.LastName;
                memberDB.Title      = model.Title;
                memberDB.CompanyId  = model.CompanyId;
                context.Members.Add(memberDB);
                context.SaveChanges();
            }
            catch (Exception e)
            {
            }
        }
예제 #8
0
        public List <MessageFromCompanyModel> GetMessagesByCompany(int CompanyId)
        {
            List <MessageFromCompany>      messages       = new List <MessageFromCompany>();
            List <MessageFromCompanyModel> messagesModels = new List <MessageFromCompanyModel>();
            AccessControlSystemEntities    context        = new AccessControlSystemEntities();

            try
            {
                messages = context.MessageFromCompanies.Where(x => x.CompanyId == CompanyId).ToList();

                foreach (var item in messages)
                {
                    messagesModels.Add(MapToMemberMessageFromCompanyModel(item, context));
                }
            }
            catch (Exception e)
            {
            }
            return(messagesModels);
        }
예제 #9
0
        public void EditMember(MemberModel model)
        {
            AccessControlSystemEntities context = new AccessControlSystemEntities();

            try
            {
                Member memberDB = context.Members.Where(x => x.Id == model.Id).FirstOrDefault();
                if (memberDB != null)
                {
                    memberDB.CardNumber = model.CardNumber;
                    memberDB.FirstName  = model.FirstName;
                    memberDB.LastName   = model.LastName;
                    memberDB.Title      = model.Title;
                }
                context.SaveChanges();
            }
            catch (Exception e)
            {
            }
        }
예제 #10
0
        public List <MemberModel> GetMembers(string CardNumber)
        {
            AccessControlSystemEntities context = new AccessControlSystemEntities();

            try
            {
                List <Member>      members      = context.Members.ToList();
                List <MemberModel> memberModels = new List <MemberModel>();
                foreach (Member item in members)
                {
                    memberModels.Add(MapToMemberModel(item, context));
                }
                return(memberModels);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(null);
        }