예제 #1
0
 public async Task <Message> GetMessage(int id)
 {
     using (EmployeePortalEntities _context = new EmployeePortalEntities())
     {
         return(await _context.Messages.FirstOrDefaultAsync(m => m.Id == id));
     }
 }
예제 #2
0
        public async Task <PagedList <Message> > GetMessagesForUser(MessageParams messageParams)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                //.Include(p => p.PostAuthor.Select(pa => pa.Author).Select(a => a.Interests))
                var messages = _context.Messages
                               .Include(u => u.User).Include(u => u.User.Photos)
                               .Include(u => u.User1).Include(u => u.User.Photos)
                               .AsQueryable();

                switch (messageParams.MessageContainer)
                {
                case "Inbox":
                    messages = messages.Where(u => u.RecipientId == messageParams.UserId && u.RecipientDeleted == false);
                    break;

                case "Outbox":
                    messages = messages.Where(u => u.SenderId == messageParams.UserId && u.SenderDeleted == false);
                    break;

                default:
                    messages = messages.Where(u => u.RecipientId == messageParams.UserId && u.RecipientDeleted == false && u.IsRead == false);
                    break;
                }

                messages = messages.OrderByDescending(d => d.MessageSent);
                return(await PagedList <Message> .CreateAsync(messages, messageParams.PageNumber, messageParams.PageSize));
            }
        }
예제 #3
0
 public void Add(User user)
 {
     using (EmployeePortalEntities _context = new EmployeePortalEntities())
     {
         _context.Users.Add(user);
     }
 }
예제 #4
0
        public IUsersDTO CreateUser(IUsersDTO usersDTO)
        {
            IUsersDTO createUserRetval = null;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    Employee employee = new Employee();
                    EntityConverter.FillEntityFromDTO(usersDTO.Employee, employee);
                    context.Employees.Add(employee);

                    User user = new User();
                    user.EmployeeId = employee.EmployeeId;
                    EntityConverter.FillEntityFromDTO(usersDTO, user);
                    context.Users.Add(user);


                    // user.UserId = usersDTO.UserId;
                    //employee.EmployeeId = usersDTO.EmployeesDTO.EmployeeId;
                    context.SaveChanges();
                    createUserRetval = usersDTO;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createUserRetval);
        }
예제 #5
0
        public IIssueHistoriesDTO UpdateIssueByAdmin(IIssueHistoriesDTO issueHistoriesDTO)
        {
            IIssueHistoriesDTO retVal = null;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    var updateIssueByAdmin = context.IssueHistories.First(item => issueHistoriesDTO.IssueId == item.IssueId);
                    if (updateIssueByAdmin != null)
                    {
                        issueHistoriesDTO.IssueHistoryId = updateIssueByAdmin.IssueHistoryId;
                        EntityConverter.FillEntityFromDTO(issueHistoriesDTO, updateIssueByAdmin);
                        context.SaveChanges();
                        retVal = issueHistoriesDTO;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(retVal);
        }
        public bool UpdateEmployee(IEmployeeDTO employeeDTO)
        {
            bool retVal = false;

            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    var employeeEntity = employeePortalEntities.Employees.FirstOrDefault(employee => employee.EmployeeId == employeeDTO.EmployeeId);
                    if (employeeEntity != null)
                    {
                        employeeEntity.FirstName = employeeDTO.FirstName;
                        employeeEntity.LastName  = employeeDTO.LastName;
                        employeeEntity.Email     = employeeDTO.Email;
                        employeePortalEntities.SaveChanges();
                        retVal = true;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }
            return(retVal);
        }
        public int InsertNotice(INoticeDTO noticeDTO)
        {
            int retVal = default(int);

            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    Notice newNotice = new Notice();
                    //EntityConverter.FillEntityFromDTO(noticeDTO, newNotice);
                    newNotice.Title          = noticeDTO.Title;
                    newNotice.Description    = noticeDTO.Description;
                    newNotice.StartDate      = noticeDTO.StartDate;
                    newNotice.ExpirationDate = noticeDTO.ExpirationDate;
                    newNotice.PostedBy       = noticeDTO.PostedById;

                    Notice addedNotice = employeePortalEntities.Notices.Add(newNotice);
                    employeePortalEntities.SaveChanges();

                    retVal = addedNotice.NoticeId;
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }
            return(retVal);
        }
예제 #8
0
 public HttpResponseMessage Put(int id, [FromBody] Employee employee)
 {
     try
     {
         using (EmployeePortalEntities entities = new EmployeePortalEntities())
         {
             var entity = entities.Employees.FirstOrDefault(x => x.Id == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with id:" + id.ToString() + " not found to update"));
             }
             else
             {
                 entity.FirstName = employee.FirstName;
                 entity.LastName  = employee.LastName;
                 entity.Gender    = employee.Gender;
                 entity.Salary    = employee.Salary;
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
        public bool UpdateNotice(INoticeDTO noticeDTO)
        {
            bool retVal = false;

            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    var noticeEntity = employeePortalEntities.Notices.FirstOrDefault(notice => notice.NoticeId == noticeDTO.NoticeId);
                    if (noticeEntity != null)
                    {
                        noticeEntity.Title          = noticeDTO.Title;
                        noticeEntity.Description    = noticeDTO.Description;
                        noticeEntity.StartDate      = noticeDTO.StartDate;
                        noticeEntity.ExpirationDate = noticeDTO.ExpirationDate;
                        employeePortalEntities.SaveChanges();
                        retVal = true;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }
            return(retVal);
        }
        public IList <IEmployeeDTO> GetAllEmployees()
        {
            IList <IEmployeeDTO> employeeDTOList = null;

            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    var employeeEntityList = employeePortalEntities.Employees;
                    if (employeeEntityList != null)
                    {
                        employeeDTOList = new List <IEmployeeDTO>();

                        foreach (var employee in employeeEntityList)
                        {
                            IEmployeeDTO employeeDTO = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.Employee);
                            EntityConverter.FillDTOFromEntity(employee, employeeDTO);
                            employeeDTOList.Add(employeeDTO);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }
            return(employeeDTOList);
        }
예제 #11
0
        public IIssuesDTO CreateIssue(IIssuesDTO issuesDTO)
        {
            IIssuesDTO createIssueRetval = null;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    Issue issue = new Issue();
                    issuesDTO.IsActive = true;
                    EntityConverter.FillEntityFromDTO(issuesDTO, issue);
                    context.Issues.Add(issue);

                    issuesDTO.IssueHistoriesDTO.AssignedTo = 1;
                    issuesDTO.IssueHistoriesDTO.Comments   = "new issue has been generated";
                    issuesDTO.IssueHistoriesDTO.ModifiedBy = 1;
                    issuesDTO.IssueHistoriesDTO.Status     = 1;
                    issuesDTO.IssueHistoriesDTO.ModifiedOn = DateTime.Now;
                    issuesDTO.IssueHistoriesDTO.IssueId    = issue.IssueId;

                    IssueHistory newissueHistory = new IssueHistory();
                    EntityConverter.FillEntityFromDTO(issuesDTO.IssueHistoriesDTO, newissueHistory);
                    context.IssueHistories.Add(newissueHistory);
                    context.SaveChanges();

                    createIssueRetval = issuesDTO;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(createIssueRetval);
        }
예제 #12
0
 public void Delete(User user)
 {
     using (EmployeePortalEntities _context = new EmployeePortalEntities())
     {
         _context.Users.Remove(user);
     }
 }
예제 #13
0
        public IList <INoticesDTO> GetActiveNotices()
        {
            List <INoticesDTO> activeNotices = new List <INoticesDTO>();

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    //check whether we need to check here whether notice is active or not
                    foreach (var notice in context.Notices.Where(item => item.IsActive == true))
                    {
                        INoticesDTO noticeDTO = (INoticesDTO)DTOFactory.Instance.Create(DTOType.NoticesDTO);
                        EntityConverter.FillDTOFromEntity(notice, noticeDTO);
                        activeNotices.Add(noticeDTO);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(activeNotices);
        }
예제 #14
0
 public IEnumerable <Employee> GetEmployees()
 {
     using (EmployeePortalEntities entities = new EmployeePortalEntities())
     {
         return(entities.Employees.ToList());
     }
 }
예제 #15
0
        public IList <INoticeDTO> GetAllNotices()
        {
            IList <INoticeDTO> noticeDTOList = null;

            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    var noticeEntityList = employeePortalEntities.Notices;
                    if (noticeEntityList != null)
                    {
                        noticeDTOList = new List <INoticeDTO>();

                        foreach (var notice in noticeEntityList)
                        {
                            INoticeDTO noticeDTO = (INoticeDTO)DTOFactory.Instance.Create(DTOType.Notice);
                            EntityConverter.FillDTOFromEntity(notice, noticeDTO);
                            noticeDTOList.Add(noticeDTO);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }
            return(noticeDTOList);
        }
예제 #16
0
        public IList <IComplexIssueDTO> GetAllActiveIssues()
        {
            IList <IComplexIssueDTO> issueDTOList = null;
            IComplexIssueDTO         issueDTO     = null;

            try
            {
                using (EmployeePortalEntities portal = new EmployeePortalEntities())
                {
                    var issueList = portal.GetAllIssuesByEmployeeId(null).ToList();
                    if (issueList.Count > 0)
                    {
                        issueDTOList = new List <IComplexIssueDTO>();
                        foreach (var issue in issueList)
                        {
                            issueDTO = (IComplexIssueDTO)DTOFactory.Instance.Create(DTOType.ComplexIssueDTO);
                            EntityConverter.FillDTOFromComplexObject(issue, issueDTO);
                            issueDTOList.Add(issueDTO);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(issueDTOList);
        }
예제 #17
0
        bool IIssuesDAC.DeleteIssue(int issueId)
        {
            bool retVal = false;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    var deleteIssue = context.Issues.First(item => item.IssueId == issueId);
                    if (deleteIssue != null)
                    {
                        deleteIssue.IsActive = false;
                        context.SaveChanges();
                        retVal = true;
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(retVal);
        }
        public IList<IEmployeeDTO> GetAllEmployees()
        {
            IList<IEmployeeDTO> employeeDTOList = null;
            using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    var employeeEntityList = employeePortalEntities.Employees;
                    if (employeeEntityList != null)
                    {
                        employeeDTOList = new List<IEmployeeDTO>();

                        foreach (var employee in employeeEntityList)
                        {
                            IEmployeeDTO employeeDTO = (IEmployeeDTO)DTOFactory.Instance.Create(DTOType.Employee);
                            EntityConverter.FillDTOFromEntity(employee, employeeDTO);
                            employeeDTOList.Add(employeeDTO);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }
            return employeeDTOList;
        }
예제 #19
0
 public async Task <bool> SaveAll()
 {
     using (EmployeePortalEntities _context = new EmployeePortalEntities())
     {
         return(await _context.SaveChangesAsync() > 0);
     }
 }
예제 #20
0
 public async Task <Photo> GetMainPhotoForUser(int userId)
 {
     using (EmployeePortalEntities _context = new EmployeePortalEntities())
     {
         return(await _context.Photos.Where(u => u.UserId == userId)
                .FirstOrDefaultAsync(p => (bool)p.IsMain));
     }
 }
예제 #21
0
 public async Task <Like> GetLike(int userId, int recipientId)
 {
     using (EmployeePortalEntities _context = new EmployeePortalEntities())
     {
         return(await _context.Likes.FirstOrDefaultAsync(u =>
                                                         u.LikerId == userId && u.LikeeId == recipientId));
     }
 }
예제 #22
0
        public async Task <Photo> GetPhoto(int id)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                var photo = await _context.Photos.FirstOrDefaultAsync(p => p.Id == id);

                return(photo);
            }
        }
예제 #23
0
        public async Task <User> GetUser(int id)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                var user = await _context.Users.Include(p => p.Photos).FirstOrDefaultAsync(u => u.Id == id);

                return(user);
            }
        }
예제 #24
0
        public async Task<bool> UserExists(string username)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                if (await _context.Users.AnyAsync(x => x.Username == username))
                    return true;

                return false;
            }
        }
예제 #25
0
        public async Task <IEnumerable <Message> > GetMessageThread(int userId, int recipientId)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                var messages = await _context.Messages
                               .Include(u => u.User).Include(p => p.User.Photos)
                               .Include(u => u.User1).Include(p => p.User1.Photos)
                               .Where(m => m.RecipientId == userId && m.RecipientDeleted == false && m.SenderId == recipientId ||
                                      m.RecipientId == recipientId && m.SenderId == userId && m.SenderDeleted == false)
                               .OrderByDescending(m => m.MessageSent)
                               .ToListAsync();

                return(messages);
            }
        }
예제 #26
0
        public async Task<User> Register(User user, string password)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                byte[] passwordHash, passwordSalt;
                CreatePasswordHash(password, out passwordHash, out passwordSalt);

                user.PasswordHash = passwordHash;
                user.PasswordSalt = passwordSalt;

                _context.Users.Add(user);
                await _context.SaveChangesAsync();

                return user;
            }
        }
예제 #27
0
        public async Task<User> Login(string username, string password)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                var user = await _context.Users.Include(p=>p.Photos).FirstOrDefaultAsync(x => x.Username == username);

                if (user == null)
                    return null;

                if (!VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
                    return null;

                return user;

            }
        }
예제 #28
0
        public async Task <PagedList <User> > GetUsers(UserParams userParams)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                var users = _context.Users.Include(p => p.Photos).OrderByDescending(u => u.LastActive).AsQueryable();

                users = users.Where(u => u.Id != userParams.UserId);

                if (userParams.Likers)
                {
                    var userLikers = await GetUserLikes(userParams.UserId, userParams.Likers);

                    users = users.Where(u => userLikers.Contains(u.Id));
                }

                if (userParams.Likees)
                {
                    var userLikees = await GetUserLikes(userParams.UserId, userParams.Likers);

                    users = users.Where(u => userLikees.Contains(u.Id));
                }

                if (userParams.MinAge != 0 || userParams.MaxAge != 99)
                {
                    var minDob = DateTime.Today.AddYears(-userParams.MaxAge - 1);
                    var maxDob = DateTime.Today.AddYears(-userParams.MinAge);

                    users = users.Where(u => u.DateOfBirth >= minDob && u.DateOfBirth <= maxDob);
                }

                if (!string.IsNullOrEmpty(userParams.OrderBy))
                {
                    switch (userParams.OrderBy)
                    {
                    case "created":
                        users = users.OrderByDescending(u => u.Created);
                        break;

                    default:
                        users = users.OrderByDescending(u => u.LastActive);
                        break;
                    }
                }
                return(await PagedList <User> .CreateAsync(users, userParams.PageNumber, userParams.PageSize));
            }
        }
예제 #29
0
 public HttpResponseMessage Post([FromBody] Employee employee)
 {
     try
     {
         using (EmployeePortalEntities entities = new EmployeePortalEntities())
         {
             entities.Employees.Add(employee);
             entities.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.Created, employee);
             message.Headers.Location = new Uri(Request.RequestUri + employee.Id.ToString());
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
예제 #30
0
        private async Task <IEnumerable <int> > GetUserLikes(int id, bool likers)
        {
            using (EmployeePortalEntities _context = new EmployeePortalEntities())
            {
                var user = await _context.Users
                           .Include(x => x.Likes)
                           .Include(x => x.Likes1)
                           .FirstOrDefaultAsync(u => u.Id == id);

                if (likers)
                {
                    return(user.Likes.Where(u => u.LikeeId == id).Select(i => i.LikerId));
                }
                else
                {
                    return(user.Likes1.Where(u => u.LikerId == id).Select(i => i.LikeeId));
                }
            }
        }
예제 #31
0
        public IDepartmentDTO GetDepartment(int departmentId)
        {
            IDepartmentDTO retVal = null;

            try
            {
                using (EmployeePortalEntities context = new EmployeePortalEntities())
                {
                    IDepartmentDTO departmentDTO = (IDepartmentDTO)DTOFactory.Instance.Create(DTOType.DepartmentDTO);
                    EntityConverter.FillDTOFromEntity(context.Departments.First(item => item.DepartmentId == departmentId), departmentDTO);
                    retVal = departmentDTO;
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.HandleException(ex);
                throw new DACException(ex.Message);
            }
            return(retVal);
        }
        public int AddEmployee(IEmployeeDTO employeeDTO, ISecurityDTO securityDTO)
        {
            int retVal = default(int);

            using(EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
            {
                try
                {
                    Employee employee = new Employee();
                    employee.EmployeeCode = employeeDTO.EmployeeCode;
                    employee.FirstName = employeeDTO.FirstName;
                    employee.LastName = employeeDTO.LastName;
                    employee.Email = employeeDTO.Email;
                    employee.DOB = employeeDTO.DOB;
                    employee.DateOfJoining = employeeDTO.DateOfJoining;
                    employee.DepartmentId = employeeDTO.DepartmentId;
                    Employee addedEmployee = employeePortalEntities.Employees.Add(employee);

                    Login login = new Login();
                    var departmentEntity = employeePortalEntities.Departments.FirstOrDefault(department => department.DepartmentId == employeeDTO.DepartmentId);
                    login.Role = (departmentEntity.DepartmentName.Equals("Administration")) ? "A" : "U";
                    login.LoginName = securityDTO.LoginName;
                    login.Password = securityDTO.Password;
                    login.EmployeeId = addedEmployee.EmployeeId;
                    employeePortalEntities.Logins.Add(login);

                    employeePortalEntities.SaveChanges();
                    retVal = addedEmployee.EmployeeId;
                }
                catch (Exception ex)
                {
                    ExceptionManager.HandleException(ex);
                    throw new DACException(ex.Message, ex);
                }
            }

            return retVal;
        }
 public bool UpdateEmployee(IEmployeeDTO employeeDTO)
 {
     bool retVal = false;
     using (EmployeePortalEntities employeePortalEntities = new EmployeePortalEntities())
     {
         try
         {
             var employeeEntity = employeePortalEntities.Employees.FirstOrDefault(employee => employee.EmployeeId == employeeDTO.EmployeeId);
             if (employeeEntity != null)
             {
                 employeeEntity.FirstName = employeeDTO.FirstName;
                 employeeEntity.LastName = employeeDTO.LastName;
                 employeeEntity.Email = employeeDTO.Email;
                 employeePortalEntities.SaveChanges();
                 retVal = true;
             }
         }
         catch (Exception ex)
         {
             ExceptionManager.HandleException(ex);
             throw new DACException(ex.Message, ex);
         }
     }
     return retVal;
 }