コード例 #1
0
        public Task <List <EventCalendarInfo> > GetAllEventCalendar(int userID, string role)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    string loginName = db.Users.Where(a => a.ID == userID).Select(a => a.LoginName).SingleOrDefault();
                    List <EventCalendarInfo> infoList = new List <EventCalendarInfo>();
                    List <EventCalendar> dataList = db.EventCalendars.Where(x => x.EventVisibility.Contains("Public") || x.EventVisibility.Contains(role)).OrderByDescending(a => a.UpdatedDate != null ? a.UpdatedDate : a.CreatedDate).ToList();
                    foreach (var data in dataList)
                    {
                        EventCalendarInfo info = new EventCalendarInfo();
                        PropertyCopier <EventCalendar, EventCalendarInfo> .Copy(data, info);
                        string photoName = db.EventCalendarPhotoes.Where(a => a.EventID == data.ID && a.IsCover == true).Select(a => a.PhotoName).SingleOrDefault();
                        info.IsFavorite = db.FavoriteLists.Any(a => a.FavoriteID == data.ID && a.UserID == userID && a.FavoriteType == "EventCalendar");
                        info.IsGoing = db.EventCalendarReacts.Any(a => a.EventID == data.ID && a.LoginName == loginName && a.Action == "Going" && a.Flag == true);
                        info.IsInterested = db.EventCalendarReacts.Any(a => a.EventID == data.ID && a.LoginName == loginName && a.Action == "Interested" && a.Flag == true);
                        info.TotalGoing = db.EventCalendarReacts.Where(a => a.EventID == data.ID && a.Action == "Going" && a.Flag == true).Count();
                        info.TotalInterested = db.EventCalendarReacts.Where(a => a.EventID == data.ID && a.Action == "Interested" && a.Flag == true).Count();
                        if (!string.IsNullOrEmpty(photoName))
                        {
                            info.CoverPhotoPath = MIUFileServer.GetFileUrl("EventCalendar/Photo", photoName);
                        }

                        infoList.Add(info);
                    }
                    return infoList;
                }
            }));
        }
コード例 #2
0
        public Task <List <NewsInfo> > GetMostViewerNews(int userID, int currentIndex, int maxRows)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    var mostViewer = db.NewsViewers.GroupBy(a => a.NewsID).Select(g => new { NewsID = g.Key, ViewCount = g.Count() }).OrderByDescending(a => a.ViewCount);

                    List <NewsInfo> dataList = db.News.Where(x => x.IsDeleted != true && x.IsDraft != true).Join(mostViewer, n => n.Id, nv => nv.NewsID, (n, nv) =>
                                                                                                                 new NewsInfo
                    {
                        Id = n.Id,
                        Title = n.Title,
                        NewsCategoryId = n.NewsCategoryId,
                        CoverPhotoPath = n.CoverPhotoPath,
                        PublishDate = n.PublishDate,
                        IsDraft = n.IsDraft,
                        IsDeleted = n.IsDeleted,
                        CreatedBy = n.CreatedBy,
                        CreatedDatetime = n.CreatedDatetime,
                        UpdatedBy = n.UpdatedBy,
                        UpdatedDatetime = n.UpdatedDatetime
                    }).ToList();


                    foreach (var data in dataList)
                    {
                        data.IsFavorite = db.FavoriteLists.Any(a => a.FavoriteID == data.Id && a.UserID == userID && a.FavoriteType == "News");
                        data.CoverPhotoPath = MIUFileServer.GetFileUrl("News/CoverPhoto", data.CoverPhotoPath);
                    }
                    int skip = currentIndex <= 1 ? 0 : (currentIndex - 1) * maxRows;
                    return dataList.Skip(skip).Take(maxRows).ToList();
                }
            }));
        }
コード例 #3
0
 public Task <List <NewsInfo> > GetNewsFavorite(int userID, int currentIndex, int maxRows)
 {
     return(Task.Run(() =>
     {
         using (MIUEntities db = new MIUEntities())
         {
             int skip = currentIndex <= 1 ? 0 : (currentIndex - 1) * maxRows;
             List <NewsInfo> dataList = (from ann in db.News
                                         join fav in db.FavoriteLists
                                         on ann.Id equals fav.FavoriteID
                                         where fav.FavoriteType == "News" &&
                                         fav.UserID == userID &&
                                         ann.IsDeleted != true &&
                                         ann.IsDraft != true
                                         orderby ann.UpdatedDatetime != null ? ann.UpdatedDatetime : ann.CreatedDatetime descending
                                         select new NewsInfo()
             {
                 Id = ann.Id,
                 Title = ann.Title,
                 NewsCategoryId = ann.NewsCategoryId,
                 CoverPhotoName = ann.CoverPhotoPath,
                 IsFavorite = true,
                 PublishDate = ann.PublishDate,
                 IsDraft = ann.IsDraft,
                 IsDeleted = ann.IsDeleted,
                 CreatedBy = ann.CreatedBy,
                 CreatedDatetime = ann.CreatedDatetime,
                 UpdatedBy = ann.UpdatedBy,
                 UpdatedDatetime = ann.UpdatedDatetime,
             }).Skip(skip).Take(maxRows).ToList <NewsInfo>();
             dataList.ForEach(a => a.CoverPhotoPath = MIUFileServer.GetFileUrl("News/CoverPhoto", a.CoverPhotoName));
             return dataList;
         }
     }));
 }
コード例 #4
0
        public Task <EditProfile> GetEditProfile(int UserID)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    try
                    {
                        User data = db.Users.Where(x => x.IsDelete != true && x.ID == UserID).SingleOrDefault();
                        EditProfile info = new EditProfile();
                        BatchInfo batchInfo = new BatchInfo();
                        CourseInfo courseInfo = new CourseInfo();
                        if (data != null)
                        {
                            PropertyCopier <User, EditProfile> .Copy(data, info);
                            if (data.DOB != null)
                            {
                                info.DOB = data.DOB.Value.Date;
                            }
                            if (!string.IsNullOrEmpty(data.ProfilePicture))
                            {
                                info.FileName = MIUFileServer.GetFileUrl("ProfileImages", data.ProfilePicture);
                            }
                        }
                        ;

                        return info;
                    }
                    catch (Exception)
                    {
                        return null;
                    }
                }
            }));
        }
コード例 #5
0
        public Task <List <NewsContentInfo> > GetNewsDetail(int newsID, int userID)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    List <NewsContent> dataList = db.NewsContents.Where(a => a.NewsId == newsID).ToList();
                    List <NewsContentInfo> infoList = new List <NewsContentInfo>();
                    foreach (var data in dataList)
                    {
                        NewsContentInfo info = new NewsContentInfo();
                        PropertyCopier <NewsContent, NewsContentInfo> .Copy(data, info);

                        if (!string.IsNullOrEmpty(info.TextContent))
                        {
                            info.ContentType = "Text";
                        }
                        else if (!string.IsNullOrEmpty(info.PhotoPath))
                        {
                            info.ContentType = "Photo";
                            info.ContentPath = MIUFileServer.GetFileUrl("News/ContentPhoto", info.PhotoPath);
                        }
                        else
                        {
                            info.ContentType = "File";
                            info.ContentPath = MIUFileServer.GetFileUrl("News/ContentFile", info.DocPath);
                        }
                        infoList.Add(info);
                    }
                    return infoList;
                }
            }));
        }
コード例 #6
0
 public Task <EventCalendarInfo> GetEventCalendarDetail(int eventID, int userID)
 {
     return(Task.Run(() =>
     {
         using (MIUEntities db = new MIUEntities())
         {
             List <EventCalendarPhoto> dataList = db.EventCalendarPhotoes.Where(a => a.EventID == eventID).ToList();
             List <EventCalendarPhotoInfo> infoList = new List <EventCalendarPhotoInfo>();
             foreach (var data in dataList)
             {
                 EventCalendarPhotoInfo info = new EventCalendarPhotoInfo();
                 PropertyCopier <EventCalendarPhoto, EventCalendarPhotoInfo> .Copy(data, info);
                 info.PhotoName = MIUFileServer.GetFileUrl("EventCalendar/Photo", info.PhotoName);
                 infoList.Add(info);
             }
             string loginName = db.Users.Where(a => a.ID == userID).Select(a => a.LoginName).SingleOrDefault();
             EventCalendar eventData = db.EventCalendars.Where(a => a.ID == eventID).SingleOrDefault();
             EventCalendarInfo eventInfo = new EventCalendarInfo();
             PropertyCopier <EventCalendar, EventCalendarInfo> .Copy(eventData, eventInfo);
             eventInfo.IsFavorite = db.FavoriteLists.Any(a => a.FavoriteID == eventData.ID && a.UserID == userID && a.FavoriteType == "EventCalendar");
             eventInfo.IsGoing = db.EventCalendarReacts.Any(a => a.EventID == eventData.ID && a.LoginName == loginName && a.Action == "Going" && a.Flag == true);
             eventInfo.IsInterested = db.EventCalendarReacts.Any(a => a.EventID == eventData.ID && a.LoginName == loginName && a.Action == "Interested" && a.Flag == true);
             eventInfo.TotalGoing = db.EventCalendarReacts.Where(a => a.EventID == eventData.ID && a.Action == "Going" && a.Flag == true).Count();
             eventInfo.TotalInterested = db.EventCalendarReacts.Where(a => a.EventID == eventData.ID && a.Action == "Interested" && a.Flag == true).Count();
             eventInfo.CoverPhotoPath = MIUFileServer.GetFileUrl("EventCalendar/Photo", infoList.Where(a => a.IsCover == true).Select(a => a.PhotoName).SingleOrDefault());
             eventInfo.photoList = infoList;
             return eventInfo;
         }
     }));
 }
コード例 #7
0
        public Task <List <MIUResourceFolderDetailInfo> > GetMIUResourceFolderDetail(int MIUResourceID, string Sorting, string Name)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    List <MIUResourceFolderDetailInfo> infoList = new List <MIUResourceFolderDetailInfo>();
                    List <MIUResourceFolderDetail> dataList = db.MIUResourceFolderDetails.Where(x => x.MIUResourceID == MIUResourceID).ToList();
                    var folderName = db.MICResourceFiles.Where(x => x.ID == MIUResourceID && x.IsFolder == 1).Select(x => x.Name).SingleOrDefault();
                    try
                    {
                        if (string.IsNullOrEmpty(Sorting) || Sorting == "\"\"")
                        {
                            dataList = dataList.OrderByDescending(x => x.CreatedDate != null ? x.CreatedDate : x.ModifiedDate).ToList();

                            if (!String.IsNullOrEmpty(Name) && Name != "\"\"")
                            {
                                dataList = dataList.Where(x => x.Name.Contains(Name)).ToList();
                            }
                        }
                        else if (Sorting == "ascending")
                        {
                            dataList = dataList.OrderBy(x => x.Name).ToList();

                            if (!String.IsNullOrEmpty(Name) && Name != "\"\"")
                            {
                                dataList = dataList.Where(x => x.Name.Contains(Name)).ToList();
                            }
                        }
                        else if (Sorting == "descending")
                        {
                            dataList = dataList.OrderByDescending(x => x.Name).ToList();

                            if (!String.IsNullOrEmpty(Name) && Name != "\"\"")
                            {
                                dataList = dataList.Where(x => x.Name.Contains(Name)).ToList();
                            }
                        }

                        foreach (var data in dataList)
                        {
                            MIUResourceFolderDetailInfo info = new MIUResourceFolderDetailInfo();

                            PropertyCopier <MIUResourceFolderDetail, MIUResourceFolderDetailInfo> .Copy(data, info);
                            info.FilePath = MIUFileServer.GetFileUrl("Resources/MIUResource/" + folderName, data.Name);
                            infoList.Add(info);
                        }

                        return infoList;
                    }
                    catch (Exception)
                    {
                        return infoList;
                    }
                }
            }));
        }
コード例 #8
0
        public Task <List <Profile> > GetStudent(int UserID)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    List <Profile> infoList = new List <Profile>();
                    try
                    {
                        List <User> dataList = db.ParentStudents.Where(x => x.ParentID == UserID).Select(x => x.User1).ToList();
                        foreach (var data in dataList)
                        {
                            Profile info = new Profile();
                            //PropertyCopier<User, Profile>.Copy(data, info);
                            //info.ProfilePicture = MIUFileServer.GetFileUrl("ProfileImages", info.ProfilePicture);
                            //info.IsFavorite = db.FavoriteLists.Any(a => a.FavoriteID == data.ID && a.UserID == userID && a.FavoriteType == "Announcement");

                            BatchInfo batchInfo = new BatchInfo();
                            CourseInfo courseInfo = new CourseInfo();
                            if (data != null)
                            {
                                PropertyCopier <User, Profile> .Copy(data, info);
                                info.ProfilePicture = MIUFileServer.GetFileUrl("ProfileImages", data.ProfilePicture);
                                Batch batch = db.BatchDetails.Where(x => x.StudentID == data.ID).Select(x => x.Batch).Where(x => x.IsDelete != true).FirstOrDefault();
                                if (batch != null)
                                {
                                    PropertyCopier <Batch, BatchInfo> .Copy(batch, batchInfo);
                                    Course course = db.Courses.Where(x => x.IsDelete != true && x.ID == batch.CourseID).SingleOrDefault();
                                    if (course != null)
                                    {
                                        PropertyCopier <Course, CourseInfo> .Copy(course, courseInfo);
                                    }
                                }

                                info.Dob = info.DOB == null ? "-" : info.DOB.Value.ToString("yyyy-MM-dd");

                                info.ApplicationDateString = info.ApplicationDate == null ? "-" : info.ApplicationDate.Value.ToString("yyyy-MM-dd");

                                info.Batch = batchInfo;
                                info.Course = courseInfo;

                                infoList.Add(info);
                            }
                        }
                        return infoList;
                    }
                    catch (Exception)
                    {
                        return infoList;
                    }
                }
            }));
        }
コード例 #9
0
        public Task <List <LecturerTimeTable> > GetLecturerTimeTable(int batchID, int lecturerID, string date)
        {
            return(Task.Run(() =>
            {
                DateTime dateTime = DateTime.Now;
                using (MIUEntities db = new MIUEntities())
                {
                    List <LecturerTimeTable> timeTables = new List <LecturerTimeTable>();
                    if (date != "\"\"" && !String.IsNullOrEmpty(date))
                    {
                        dateTime = Convert.ToDateTime(date);
                    }
                    if (batchID != 0)
                    {
                        timeTables = (from p in db.vProgramPlans
                                      join u in db.Users on p.LectureID equals u.ID
                                      join b in db.Batches on p.BatchID equals b.ID
                                      join m in db.Modules on p.ModuleID equals m.ID
                                      join c in db.Courses on b.CourseID equals c.ID
                                      join t in db.TimeTableDetails on p.TermDetailID equals t.TermDetailID
                                      where b.ID == batchID && u.ID == lecturerID && DbFunctions.TruncateTime(t.Date) == dateTime.Date
                                      select new LecturerTimeTable
                        {
                            LecturerID = u.ID,
                            LoginName = u.LoginName,
                            FullName = u.FullName,
                            ProfilePicture = u.ProfilePicture,
                            ProfilePicture2 = u.ProfilePicture2,
                            CourseName = c.CourseName,
                            ModuleCode = m.ModuleCode,
                            ModuleName = m.ModuleName,
                            StartTime = t.StartTime,
                            EndTime = t.EndTime,
                            TimeTableDate = t.Date
                        }).ToList();

                        foreach (var data in timeTables)
                        {
                            data.ProfilePicture = MIUFileServer.GetFileUrl("ProfileImages", data.ProfilePicture);
                            data.ProfilePicture2 = data.ProfilePicture2 != null? MIUFileServer.GetFileUrl("ProfileImages", data.ProfilePicture2):"";
                        }
                    }

                    return timeTables;
                }
            }));
        }
コード例 #10
0
        public Task <Profile> GetProfile(int UserID)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    Profile info = new Profile();
                    try
                    {
                        User data = db.Users.Where(x => x.IsDelete != true /*&& x.UserType == 1*/ && x.ID == UserID).SingleOrDefault();

                        BatchInfo batchInfo = new BatchInfo();
                        CourseInfo courseInfo = new CourseInfo();
                        if (data != null)
                        {
                            PropertyCopier <User, Profile> .Copy(data, info);
                            info.ProfilePicture = MIUFileServer.GetFileUrl("ProfileImages", data.ProfilePicture);
                            Batch batch = db.BatchDetails.Where(x => x.StudentID == data.ID).Select(x => x.Batch).Where(x => x.IsDelete != true).FirstOrDefault();
                            if (batch != null)
                            {
                                PropertyCopier <Batch, BatchInfo> .Copy(batch, batchInfo);
                                Course course = db.Courses.Where(x => x.IsDelete != true && x.ID == batch.CourseID).SingleOrDefault();
                                if (course != null)
                                {
                                    PropertyCopier <Course, CourseInfo> .Copy(course, courseInfo);
                                }
                            }

                            info.Dob = info.DOB == null ? "-" : info.DOB.Value.ToString("yyyy-MM-dd");

                            info.ApplicationDateString = info.ApplicationDate == null ? "-" : info.ApplicationDate.Value.ToString("yyyy-MM-dd");

                            info.Batch = batchInfo;
                            info.Course = courseInfo;
                        }

                        return info;
                    }
                    catch (Exception)
                    {
                        return info;
                    }
                }
            }));
        }
コード例 #11
0
        public Task <NewsInfo> GetNewsByID(int userID, int newsID)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    News data = db.News.Where(x => x.Id == newsID && x.IsDeleted != true && x.IsDraft != true).SingleOrDefault();

                    NewsInfo info = new NewsInfo();
                    PropertyCopier <News, NewsInfo> .Copy(data, info);
                    info.IsFavorite = db.FavoriteLists.Any(a => a.FavoriteID == data.Id && a.UserID == userID && a.FavoriteType == "News");
                    info.CoverPhotoPath = MIUFileServer.GetFileUrl("News/CoverPhoto", info.CoverPhotoPath);
                    info.Description = db.NewsContents.Where(x => x.NewsId == data.Id).Select(x => x.TextContent).FirstOrDefault();

                    return info;
                }
            }));
        }
コード例 #12
0
 public Task <TopNewsInfo> GetTopNews(int userID)
 {
     return(Task.Run(() =>
     {
         using (MIUEntities db = new MIUEntities())
         {
             News data = db.News.Where(x => x.IsDeleted != true && x.IsDraft != true).OrderByDescending(a => a.PublishDate).OrderByDescending(a => a.CreatedDatetime).Take(1).FirstOrDefault();
             TopNewsInfo info = new TopNewsInfo()
             {
                 NewsId = data.Id,
                 Title = data.Title,
                 CreatedDatetime = data.CreatedDatetime,
                 PhotoPath = MIUFileServer.GetFileUrl("News/CoverPhoto", data.CoverPhotoPath),
                 TextContent = db.NewsContents.Where(a => a.NewsId == data.Id && a.TextContent != null).Take(1).Select(a => a.TextContent).SingleOrDefault()
             };
             return info;
         }
     }));
 }
コード例 #13
0
 public Task <List <EventCalendarInfo> > GetEventCalendarFavorite(int userID, string role)
 {
     return(Task.Run(() =>
     {
         using (MIUEntities db = new MIUEntities())
         {
             List <EventCalendarInfo> dataList = (from ann in db.EventCalendars
                                                  join fav in db.FavoriteLists
                                                  on ann.ID equals fav.FavoriteID
                                                  join eventPhoto in db.EventCalendarPhotoes
                                                  on ann.ID equals eventPhoto.EventID
                                                  where fav.FavoriteType == "EventCalendar" &&
                                                  (ann.EventVisibility.Contains("Public") || ann.EventVisibility.Contains(role)) &&
                                                  eventPhoto.IsCover == true && fav.UserID == userID
                                                  //orderby ann.UpdatedDate != null ? ann.UpdatedDate : ann.CreatedDate descending
                                                  orderby ann.StartDate
                                                  select new EventCalendarInfo()
             {
                 ID = ann.ID,
                 Title = ann.Title,
                 StartDate = ann.StartDate,
                 EndDate = ann.EndDate,
                 StartTime = ann.StartTime,
                 EndTime = ann.EndTime,
                 Location = ann.Location,
                 CoverPhotoName = eventPhoto.PhotoName,
                 IsFavorite = true
             }).ToList <EventCalendarInfo>();
             string loginName = db.Users.Where(a => a.ID == userID).Select(a => a.LoginName).SingleOrDefault();
             foreach (var info in dataList)
             {
                 info.IsGoing = db.EventCalendarReacts.Any(a => a.EventID == info.ID && a.LoginName == loginName && a.Action == "Going" && a.Flag == true);
                 info.IsInterested = db.EventCalendarReacts.Any(a => a.EventID == info.ID && a.LoginName == loginName && a.Action == "Interested" && a.Flag == true);
                 info.TotalGoing = db.EventCalendarReacts.Where(a => a.EventID == info.ID && a.Action == "Going" && a.Flag == true).Count();
                 info.TotalInterested = db.EventCalendarReacts.Where(a => a.EventID == info.ID && a.Action == "Interested" && a.Flag == true).Count();
                 info.CoverPhotoPath = MIUFileServer.GetFileUrl("EventCalendar/Photo", info.CoverPhotoName);
             }
             return dataList;
         }
     }));
 }
コード例 #14
0
        public Task <List <EventInfo> > GetEvent(int Take)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    List <EventInfo> infoList = new List <EventInfo>();
                    List <Event> List = new List <Event>();
                    try
                    {
                        List = db.Events.Where(x => x.Status != true).OrderByDescending(x => x.ModifiedDate != null ? x.ModifiedDate : x.CreatedDate).ToList();

                        if (Take != 0)
                        {
                            List = List.Take(Take).ToList();
                        }

                        foreach (var data in List)
                        {
                            EventInfo info = new EventInfo();
                            PropertyCopier <Event, EventInfo> .Copy(data, info);
                            //data.EventDetails = db.EventDetails.Where(x => x.EventID == data.ID).ToList();

                            foreach (var detail in data.EventDetails)
                            {
                                EventDetailInfo detailinfo = new EventDetailInfo();
                                PropertyCopier <EventDetail, EventDetailInfo> .Copy(detail, detailinfo);
                                detail.FileName = MIUFileServer.GetFileUrl("EventCalendar", detail.FileName);
                            }
                            infoList.Add(info);
                        }
                    }
                    catch (Exception)
                    {
                    }

                    return infoList;
                }
            }));
        }
コード例 #15
0
        public Task <List <UserInfo> > GetReportAttendanceList(int batchID, string StudentName)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    List <UserInfo> infoList = new List <UserInfo>();
                    List <User> stdList = new List <User>();
                    //try
                    //{
                    if (batchID != 0)
                    {
                        stdList = (from a in db.BatchDetails
                                   join b in db.Users on a.StudentID equals b.ID
                                   where a.BatchID == batchID && b.UserType == 1 && b.IsDelete != true
                                   select b).OrderBy(x => x.FullName).ToList();

                        if (StudentName != "")
                        {
                            stdList = stdList.Where(x => x.FullName.Contains(StudentName)).ToList();
                        }

                        foreach (var data in stdList)
                        {
                            UserInfo info = new UserInfo();
                            PropertyCopier <User, UserInfo> .Copy(data, info);
                            info.ProfilePicture = MIUFileServer.GetFileUrl("ProfileImages", data.ProfilePicture);
                            info.ProfilePicture2 = MIUFileServer.GetFileUrl("ProfileImages", data.ProfilePicture2);
                            infoList.Add(info);
                        }
                    }
                    return infoList;
                    //}
                    //catch (Exception)
                    //{
                    //    return infoList;
                    //}
                }
            }));
        }
コード例 #16
0
 public Task <List <NewsInfo> > GetRecentNews(int userID, int perviousDay)
 {
     return(Task.Run(() =>
     {
         using (MIUEntities db = new MIUEntities())
         {
             DateTime fromDate = DateTime.Now.AddDays(-perviousDay); //last pervious day
             DateTime toDate = DateTime.Now;                         //today
             List <NewsInfo> infoList = new List <NewsInfo>();
             List <News> dataList = db.News.Where(a => a.IsDeleted != true && a.IsDraft != true && DbFunctions.TruncateTime(a.PublishDate) >= DbFunctions.TruncateTime(fromDate) && DbFunctions.TruncateTime(a.PublishDate) <= DbFunctions.TruncateTime(toDate)).ToList();
             foreach (var data in dataList)
             {
                 NewsInfo info = new NewsInfo();
                 PropertyCopier <News, NewsInfo> .Copy(data, info);
                 info.IsFavorite = db.FavoriteLists.Any(a => a.FavoriteID == data.Id && a.UserID == userID && a.FavoriteType == "News");
                 info.CoverPhotoPath = MIUFileServer.GetFileUrl("News/CoverPhoto", info.CoverPhotoPath);
                 infoList.Add(info);
             }
             return infoList;
         }
     }));
 }
コード例 #17
0
 public Task <List <NewsInfo> > GetNews(int userID, int currentIndex, int maxRows)
 {
     return(Task.Run(() =>
     {
         using (MIUEntities db = new MIUEntities())
         {
             int skip = currentIndex <= 1 ? 0 : (currentIndex - 1) * maxRows;
             List <NewsInfo> infoList = new List <NewsInfo>();
             List <NewsContentInfo> contentinfoList = new List <NewsContentInfo>();
             List <News> dataList = db.News.Where(x => x.IsDeleted != true && x.IsDraft != true).OrderByDescending(a => a.PublishDate).OrderByDescending(a => a.CreatedDatetime).Skip(skip).Take(maxRows).ToList();
             foreach (var data in dataList)
             {
                 NewsInfo info = new NewsInfo();
                 PropertyCopier <News, NewsInfo> .Copy(data, info);
                 info.IsFavorite = db.FavoriteLists.Any(a => a.FavoriteID == data.Id && a.UserID == userID && a.FavoriteType == "News");
                 info.CoverPhotoPath = MIUFileServer.GetFileUrl("News/CoverPhoto", info.CoverPhotoPath);
                 info.Description = db.NewsContents.Where(x => x.NewsId == data.Id).Select(x => x.TextContent).FirstOrDefault();
                 infoList.Add(info);
             }
             return infoList;
         }
     }));
 }
コード例 #18
0
        public Task <List <MIUPaymentInfo> > GetPayment(int courseID, int batchID, int?userID, string year, string month, string type, int currentIndex, int maxRows)
        {
            int Year = int.Parse(year);

            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    int skip = currentIndex <= 1 ? 0 : (currentIndex - 1) * maxRows;
                    List <MIUPaymentInfo> infoList = new List <MIUPaymentInfo>();

                    List <MIUPaymentDetailInfo> infoDetailList = new List <MIUPaymentDetailInfo>();

                    var Month = DateTime.Now.Month;
                    if (month != "")
                    {
                        Month = Convert.ToDateTime(month + "01," + DateTime.Now.Year).Month;
                    }
                    List <MIUPayment> data = db.MIUPayments.Where(x => (courseID == 0 ? true : x.CourseID == courseID) &&
                                                                  (batchID == 0 ? true : x.BatchID == batchID) &&
                                                                  (userID == 0 ? true : x.StudentID == userID)
                                                                  ).ToList();

                    List <MIUPaymentDetail> dataDetail = new List <MIUPaymentDetail>();
                    MIUPaymentInfo info = new MIUPaymentInfo();
                    foreach (var item in data)
                    {
                        dataDetail = item.MIUPaymentDetails.Where(x =>

                                                                  (x.MIUPaymentID == item.ID)

                                                                  && (

                                                                      //payment duedate
                                                                      (
                                                                          x.PaymentDueDate.Value.Year == Year &&
                                                                          x.PaymentDueDate.Value.Month == Month
                                                                      )
                                                                      ||

                                                                      //payent received date
                                                                      (
                                                                          x.PaymentReceivedDate != null &&
                                                                          x.PaymentReceivedDate.Value.Year == Year &&
                                                                          x.PaymentReceivedDate.Value.Month == Month
                                                                      )
                                                                      )

                                                                  ).ToList();


                        if (type == "Received")
                        {
                            dataDetail = dataDetail.Where(x => x.PaymentStatus == type).ToList();
                        }
                        else if (type == "Overdued")
                        {
                            dataDetail = dataDetail.Where(x => x.PaymentDueDate.Value.Date < DateTime.Now.Date && x.PaymentStatus == null).ToList();
                        }
                        else
                        {
                            dataDetail = dataDetail.OrderByDescending(x => x.PaymentReceivedDate).ToList();
                        }


                        foreach (var item1 in dataDetail)
                        {
                            int amount = 0;
                            int.TryParse(item1.Amount, out amount);
                            MIUPaymentDetailInfo detailInfo = new MIUPaymentDetailInfo()
                            {
                                StudentID = item.User.ID,
                                ProfilePicture = MIUFileServer.GetFileUrl("ProfileImages", item.User.ProfilePicture),
                                StudentName = item.User.FullName,
                                LoginName = item.User.LoginName,
                                CourseName = item.Course.CourseName,
                                BatchName = item.Batch.BatchName,
                                TermName = item1.Term.TermName,
                                ReceivedOn = item1.PaymentReceivedDate,
                                PaymentDueDate = item1.PaymentDueDate,
                                PaymentStatus = item1.PaymentStatus,
                                Benefit = item1.Benefit,
                                Amount = amount,
                            };

                            //if (String.IsNullOrEmpty(item1.PaymentStatus) && item1.PaymentDueDate < DateTime.Now.Date)
                            //{
                            //    detailInfo.PaymentStatus = "Overdued";
                            //    info.OverduePayment += amount;
                            //}
                            //else if (item1.PaymentStatus == "Received")
                            //{
                            //    info.TotalEarned += amount;
                            //}
                            //else
                            //{
                            //    detailInfo.PaymentStatus = "Pending";
                            //    pending += amount;
                            //}
                            //info.EstimatedIncome = info.OverduePayment + info.TotalEarned + pending;

                            infoDetailList.Add(detailInfo);
                            info.MIUPaymentDetailInfo = infoDetailList.Skip(skip).Take(maxRows).ToList();
                        }
                    }

                    //to calculate total amount will calculate depends on BatchID, CourseID, StudentID

                    //total earned
                    var totalEarned = (
                        from p in db.MIUPayments
                        join pd in db.MIUPaymentDetails
                        on p.ID equals pd.MIUPaymentID
                        where
                        (
                            (courseID == 0 ? true : p.CourseID == courseID) &&
                            (batchID == 0 ? true : p.BatchID == batchID) &&
                            (userID == 0 ? true : p.StudentID == userID) &&
                            (pd.PaymentReceivedDate.Value.Year == Year) &&
                            (string.IsNullOrEmpty(month) ? true : pd.PaymentReceivedDate.Value.Month == Month) &&
                            (pd.PaymentStatus == "Received")
                        )
                        select pd.Amount
                        ).ToList();

                    foreach (var earn in totalEarned)
                    {
                        double en = Convert.ToDouble(earn);
                        info.TotalEarned += en;
                    }

                    //overdue will calculate status == pending
                    var now = DateTime.Now;
                    var totalOverdue = (
                        from p in db.MIUPayments
                        join pd in db.MIUPaymentDetails
                        on p.ID equals pd.MIUPaymentID
                        where
                        (
                            (courseID == 0 ? true : p.CourseID == courseID) &&
                            (batchID == 0 ? true : p.BatchID == batchID) &&
                            (userID == 0 ? true : p.StudentID == userID) &&
                            pd.PaymentDueDate.Value.Year == Year && pd.PaymentDueDate.Value.Month == Month &&
                            (pd.PaymentStatus == "Pending" || pd.PaymentStatus == null || pd.PaymentStatus == "") &&
                            DbFunctions.TruncateTime(pd.PaymentDueDate.Value) < DbFunctions.TruncateTime(now)
                        )
                        select pd.Amount
                        ).ToList();


                    foreach (var earn in totalOverdue)
                    {
                        double en = Convert.ToDouble(earn);
                        info.OverduePayment += en;
                    }

                    //Estimate income
                    var totalEstimateIncome = (
                        from p in db.MIUPayments
                        join pd in db.MIUPaymentDetails
                        on p.ID equals pd.MIUPaymentID
                        where
                        (
                            (courseID == 0 ? true : p.CourseID == courseID) &&
                            (batchID == 0 ? true : p.BatchID == batchID) &&
                            (userID == 0 ? true : p.StudentID == userID) &&
                            pd.PaymentDueDate.Value.Year == Year && pd.PaymentDueDate.Value.Month == Month
                        )
                        select pd.Amount
                        ).ToList();


                    foreach (var earn in totalEstimateIncome)
                    {
                        double en = Convert.ToDouble(earn);
                        info.EstimatedIncome += en;
                    }

                    infoList.Add(info);

                    return infoList;
                }
            }));
        }
コード例 #19
0
        public Task <AttendanceGrid> GetReportAttendance(int batchID, int studentID)
        {
            return(Task.Run(async() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    //try
                    //{
                    if (batchID != 0)
                    {
                        string modulecodelist = "";
                        AttendanceGrid grid = new AttendanceGrid();

                        //var terms = db.Terms.AsNoTracking().Where(x => x.BatchID == batchID).Select(x => new { ID = x.ID, TermName = x.TermName, StartDate = x.StartDate, sortOrer = x.sortOrder }).OrderBy(y => y.sortOrer).ToList();
                        List <Term> terms = db.Terms.AsNoTracking().Where(x => x.BatchID == batchID).OrderBy(y => y.sortOrder).ToList();

                        AttRateAndPercent attRateAndPercent = new AttRateAndPercent();
                        attRateAndPercent = await GetAttRateAndPercent(batchID, studentID);

                        grid.AttendanceRateTermName = attRateAndPercent.AttendanceRateTermName;
                        grid.AttendanceRatePercent = attRateAndPercent.AttenddanceRatePercent;

                        List <TermInfo> terminfo = new List <TermInfo>();

                        foreach (var data in terms)
                        {
                            TermInfo info = new TermInfo();
                            PropertyCopier <Term, TermInfo> .Copy(data, info);
                            //info.IsFavorite = db.FavoriteLists.Any(a => a.FavoriteID == data.ID && a.UserID == userID && a.FavoriteType == "Announcement");
                            terminfo.Add(info);
                        }

                        var termlist = db.Terms.AsNoTracking().Where(x => x.BatchID == batchID).Select(x => x.ID).ToList();
                        var frommonth = DateTime.Now.AddMonths(-24);
                        var tomonth = DateTime.Now.AddMonths(24);
                        var attendances = db.Attendances.AsNoTracking().Where(x => x.Date >= frommonth && x.Date <= tomonth && termlist.Contains(x.TermID)).ToList();

                        grid.TermDetail = terminfo;

                        //For Module Code List Of Header

                        foreach (var term in terms)
                        {
                            List <TermDetail> tds = db.TermDetails.AsNoTracking().Where(td => td.TermID == term.ID && td.Attendence == true).ToList();

                            modulecodelist = "";
                            foreach (var td in tds)
                            {
                                if (modulecodelist != "")
                                {
                                    modulecodelist += ",";
                                }
                                modulecodelist += td.Module.ModuleCode;
                            }

                            foreach (TermInfo item in grid.TermDetail)
                            {
                                if (item.ID == term.ID)
                                {
                                    item.ModuleCodeList = modulecodelist;
                                }
                            }

                            //grid.ModuleCodeList.Add(modulecodelist);

                            int count = attendances.Where(a => a.TermID == term.ID).GroupBy(a => a.Month).Count();
                            grid.MonthList.Add(count);
                        }


                        //For Row of Grid
                        List <UserInfo> stdList = new List <UserInfo>();
                        if (studentID != 0)
                        {
                            stdList = (from a in db.BatchDetails
                                       join b in db.Users on a.StudentID equals b.ID
                                       where a.BatchID == batchID && b.ID == studentID && b.UserType == 1 && b.IsDelete != true
                                       select new UserInfo {
                                ID = b.ID, FullName = b.FullName, LoginName = b.LoginName, ProfilePicture = b.ProfilePicture, ProfilePicture2 = b.ProfilePicture2
                            }).ToList();
                        }
                        else
                        {
                            stdList = (from a in db.BatchDetails
                                       join b in db.Users on a.StudentID equals b.ID
                                       where a.BatchID == batchID && b.UserType == 1 && b.IsDelete != true
                                       select new UserInfo {
                                ID = b.ID, FullName = b.FullName, LoginName = b.LoginName, ProfilePicture = b.ProfilePicture, ProfilePicture2 = b.ProfilePicture2
                            }).ToList();
                            //stdList = db.BatchDetails.AsNoTracking().Where(x => x.BatchID == batchID).Select(x => x.User).Where(x => x.UserType == 1 && x.IsDelete == null || x.IsDelete != true).ToList();
                        }

                        //var frommonth = DateTime.Now.AddMonths(-6);
                        //var tomonth = DateTime.Now.AddMonths(6);
                        //var attendances = db.Attendances.Where(x => x.Date >= frommonth && x.Date <= tomonth);

                        //decimal SutdentCountYear1 = 0;
                        //decimal SutdentCountYear2 = 0;
                        //decimal StudentLastYear = 0;
                        //decimal StudentFoundation = 0;

                        if (stdList.Count() > 0)
                        {
                            foreach (UserInfo student in stdList)
                            {
                                //AttendanceGridRow row = new AttendanceGridRow();
                                //row.StudentName = student.FullName;
                                //row.StudentID = student.LoginName;
                                var attendance = attendances.Where(x => x.StudentID == student.ID);

                                decimal TotalYear1 = 0;
                                decimal TotalYear2 = 0;
                                decimal TotalLastYear = 0;
                                decimal TotalFoundation = 0;
                                int Year2Count = 0;
                                int LastYearCount = 0;
                                int FoundationCount = 0;
                                foreach (var term in terms)
                                {
                                    int percentageValue1 = 0; int percentageValue2 = 0;

                                    //double attendingCount = 0;
                                    double totalCount1 = 0; double totalCount2 = 0; double totalCount = 0; double attendingTotalCount = 0;

                                    int daysOfFirstMonth = endOfMonth(term.StartDate.Value.Month, term.StartDate.Value.Year) - term.StartDate.Value.Day;
                                    int firstMonth = daysOfFirstMonth > 5 ? term.StartDate.Value.Month : term.StartDate.Value.AddMonths(1).Month;
                                    totalCount1 = attendance.Where(x => x.TermID == term.ID && x.Month <= firstMonth).Select(y => y.ID).Count();
                                    totalCount2 = attendance.Where(x => x.TermID == term.ID && x.Month > firstMonth).Select(y => y.ID).Count();
                                    totalCount = attendance.Where(x => x.TermID == term.ID).Select(y => y.ID).Count();

                                    AttendanceCell cell1 = new AttendanceCell();
                                    AttendanceCell cell2 = new AttendanceCell();
                                    AttendanceCell totalcell = new AttendanceCell();

                                    totalCount1 = attendance.Where(x => x.TermID == term.ID && x.Month <= firstMonth).Select(y => y.ID).Count();
                                    if (totalCount1 > 0)
                                    {
                                        var attendingList1 = attendance.Where(x => x.TermID == term.ID && x.IsAttending == true && x.Month <= firstMonth).Select(y => y.ID).Count();

                                        if (attendingList1 != 0 && attendingList1 > 0)
                                        {
                                            attendingTotalCount += attendingList1;
                                            percentageValue1 = (int)Math.Round(((attendingList1 / totalCount1) * 100));
                                        }
                                    }
                                    if (totalCount2 > 0)
                                    {
                                        var attendingList2 = attendance.Where(x => x.TermID == term.ID && x.IsAttending == true && x.Month > firstMonth).Select(y => y.ID).Count();
                                        if (attendingList2 != 0 && attendingList2 > 0)
                                        {
                                            //attendingCount = count2;
                                            attendingTotalCount += attendingList2;
                                            percentageValue2 = (int)Math.Round(((attendingList2 / totalCount2) * 100));
                                            //percentageValue2 = (int)(((attendingCount / totalCount2) * 100));
                                            //percentagedouble2 = (count2 / totalCount2) * 100;
                                        }
                                    }
                                    cell1.Value = percentageValue1;
                                    cell2.Value = percentageValue2;
                                    //totalcell.Value = (int)Math.Round((((double)percentageValue1+(double)percentageValue2)*100)/200);
                                    //totalcell.Value = (int)Math.Round((((double)percentagedouble1 + (double)percentagedouble2) * 100) / 200);
                                    if (totalCount > 0)
                                    {
                                        //totalCount = attendance.Where(x => x.TermID == term.ID).Count();
                                        totalcell.Value = (int)Math.Round(((attendingTotalCount / totalCount) * 100));

                                        if (term.TermCode == "Term-2" || term.TermCode == "Term-3" || term.TermCode == "Term-4" || term.TermCode == "Term-5")
                                        {
                                            TotalYear1 += totalcell.Value;
                                        }
                                        else if (term.TermCode == "Term-6" || term.TermCode == "Term-7" || term.TermCode == "Term-8" || term.TermCode == "Term-9")
                                        {
                                            Year2Count++;
                                            TotalYear2 += totalcell.Value;
                                        }
                                        else if (term.TermCode == "Term-10" || term.TermCode == "Term-11" || term.TermCode == "Term-12" || term.TermCode == "Term-13")
                                        {
                                            LastYearCount++;
                                            TotalLastYear += totalcell.Value;
                                        }
                                        else
                                        {
                                            FoundationCount++;
                                            TotalFoundation += totalcell.Value;
                                        }
                                    }
                                    else
                                    {
                                        totalcell.Value = 0;

                                        if (term.TermCode == "Term-2" || term.TermCode == "Term-3" || term.TermCode == "Term-4" || term.TermCode == "Term-5")
                                        {
                                            TotalYear1 += totalcell.Value;
                                        }
                                        else if (term.TermCode == "Term-6" || term.TermCode == "Term-7" || term.TermCode == "Term-8" || term.TermCode == "Term-9")
                                        {
                                            Year2Count++;
                                            TotalYear2 += totalcell.Value;
                                        }
                                        else if (term.TermCode == "Term-10" || term.TermCode == "Term-11" || term.TermCode == "Term-12" || term.TermCode == "Term-13")
                                        {
                                            LastYearCount++;
                                            TotalLastYear += totalcell.Value;
                                        }
                                        else
                                        {
                                            FoundationCount++;
                                            TotalFoundation += totalcell.Value;
                                        }
                                    }
                                    //row.cells.Add(cell1);
                                    //row.cells.Add(cell2);
                                    //row.cells.Add(totalcell);
                                    grid.StudentID = student.ID;
                                    grid.StudentName = student.FullName;
                                    grid.LoginName = student.LoginName;
                                    grid.BatchName = term.Batch.BatchName;
                                    grid.CourseName = term.Batch.Course.CourseName;
                                    grid.ProfilePicture = MIUFileServer.GetFileUrl("ProfileImages", student.ProfilePicture);
                                    grid.ProfilePicture2 = MIUFileServer.GetFileUrl("ProfileImages", student.ProfilePicture2);
                                    //grid.ProfilePicture2 = student.ProfilePicture2;
                                    foreach (TermInfo item in grid.TermDetail)
                                    {
                                        if (item.ID == term.ID)
                                        {
                                            //item.StudentID = student.ID;
                                            //item.StudentName = student.FullName;
                                            item.First = percentageValue1;
                                            item.Second = percentageValue2;
                                            item.Total = totalcell.Value;
                                        }
                                    }
                                }
                                //decimal a = 0;
                                //decimal b = 0;
                                //decimal c = 0;
                                //decimal d = 0;

                                //if (TotalYear1 > 0)
                                //{
                                //    a = Math.Round(TotalYear1 / 4);
                                //}
                                //if (TotalYear2 > 0)
                                //{
                                //    b = Math.Round(TotalYear2 / Year2Count);
                                //}
                                //if (TotalFoundation > 0)
                                //{
                                //    c = Math.Round(TotalFoundation / FoundationCount);
                                //}
                                //if (TotalLastYear > 0)
                                //{
                                //    d = Math.Round(TotalLastYear / LastYearCount);
                                //}

                                //if (a >= 70)
                                //{
                                //    SutdentCountYear1++;
                                //}
                                //if (b >= 70)
                                //{
                                //    SutdentCountYear2++;
                                //}
                                //if (c >= 70)
                                //{
                                //    StudentFoundation++;
                                //}
                                //if (d >= 70)
                                //{
                                //    StudentLastYear++;
                                //}
                                //grid.Rows.Add(row);
                            }
                        }
                        int index = 0;
                        foreach (var item in grid.TermDetail)
                        {
                            if (index == 0)
                            {
                                item.YearName = "Foundation";
                            }
                            else if (index > 0 && index <= 4)
                            {
                                item.YearName = "Year 1";
                            }
                            else if (index > 4 && index <= 8)
                            {
                                item.YearName = "Year 2";
                            }
                            else
                            {
                                item.YearName = "";
                            }
                            index++;
                        }
                        return grid;
                    }
                    else
                    {
                        return null;
                    }
                    //}
                    //catch (Exception)
                    //{
                    //    return null;
                    //}
                }
            }));
        }
コード例 #20
0
        public Task <ReturnStudyResource> GetStudyResource(int moduleID, string Sorting)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    ReturnStudyResource StudyResource = new ReturnStudyResource();
                    List <RecommendedEbookInfo> BookInfoList = new List <RecommendedEbookInfo>();
                    List <StudyResourceDetailInfo> SRInfoList = new List <StudyResourceDetailInfo>();
                    StudyResourceInfoList studyResourceInfoList = new StudyResourceInfoList();
                    try
                    {
                        #region LearningOutcome

                        LearningOutcomeInfo learningOutcomeInfo = new LearningOutcomeInfo();

                        List <LearningOutcome> lcs = db.LearningOutcomes.Where(x => x.ModuleID == moduleID).ToList();

                        List <LearningOutcomeInfoList> LearningOutcomeInfoList = new List <LearningOutcomeInfoList>();

                        List <AssignmentCriteriaInfo> AssignmentCriterias = new List <AssignmentCriteriaInfo>();

                        List <AssignmentCriteriaDetailInfo> AssignmentCriteriaDetails = new List <AssignmentCriteriaDetailInfo>();
                        foreach (var lc in lcs)
                        {
                            LearningOutcomeInfoList LearningOutcome = new LearningOutcomeInfoList();
                            LearningOutcome.AssignmentCriteriaInfo = new List <AssignmentCriteriaInfo>();
                            LearningOutcome.AssignmentCriteriaDetailInfo = new List <AssignmentCriteriaDetailInfo>();
                            PropertyCopier <LearningOutcome, LearningOutcomeInfoList> .Copy(lc, LearningOutcome);

                            foreach (var ac in lc.AssignmentCriterias)
                            {
                                if (lc.ID == ac.LearningOutcomeID)
                                {
                                    AssignmentCriteriaInfo AssignmentCriteriaInfo = new AssignmentCriteriaInfo();
                                    PropertyCopier <AssignmentCriteria, AssignmentCriteriaInfo> .Copy(ac, AssignmentCriteriaInfo);
                                    LearningOutcome.AssignmentCriteriaInfo.Add(AssignmentCriteriaInfo);
                                }


                                foreach (var acd in ac.AssignmentCriteriaDetails)
                                {
                                    if (acd.AssignmentCriteriaID == ac.ID)
                                    {
                                        AssignmentCriteriaDetailInfo AssignmentCriteriaDetailInfo = new AssignmentCriteriaDetailInfo();
                                        PropertyCopier <AssignmentCriteriaDetail, AssignmentCriteriaDetailInfo> .Copy(acd, AssignmentCriteriaDetailInfo);
                                        LearningOutcome.AssignmentCriteriaDetailInfo.Add(AssignmentCriteriaDetailInfo);
                                    }
                                }
                            }
                            LearningOutcomeInfoList.Add(LearningOutcome);
                        }

                        learningOutcomeInfo.LearningOutcomeInfoList = LearningOutcomeInfoList;

                        #endregion

                        var items = db.StudyResources.Where(s => s.ModuleID == moduleID);
                        if (items != null && items.Count() > 0)
                        {
                            StudyResource studyResource = new StudyResource();
                            studyResource = items.First();
                            PropertyCopier <StudyResource, StudyResourceInfoList> .Copy(studyResource, studyResourceInfoList);

                            List <StudyResourceDetail> StudyResourceDetails = studyResource.StudyResourceDetails.ToList();
                            foreach (var StudyResourceDetail in StudyResourceDetails)
                            {
                                StudyResourceDetailInfo srinfo = new StudyResourceDetailInfo();
                                PropertyCopier <StudyResourceDetail, StudyResourceDetailInfo> .Copy(StudyResourceDetail, srinfo);
                                srinfo.Name = MIUFileServer.GetFileUrl("Resource/" + moduleID, srinfo.Name);
                                SRInfoList.Add(srinfo);
                            }

                            List <RecommendedEbook> recommendedEbooks = studyResource.RecommendedEbooks.ToList();
                            foreach (var recommendedEbook in recommendedEbooks)
                            {
                                RecommendedEbookInfo bookinfo = new RecommendedEbookInfo();
                                PropertyCopier <RecommendedEbook, RecommendedEbookInfo> .Copy(recommendedEbook, bookinfo);
                                bookinfo.Name = MIUFileServer.GetFileUrl("Resource/" + moduleID, bookinfo.Name);
                                BookInfoList.Add(bookinfo);
                            }
                        }
                        StudyResource.LearningOutcomeInfo = learningOutcomeInfo;

                        switch (Sorting)
                        {
                        case "all": StudyResource.RecommendedEbookInfo = BookInfoList.OrderByDescending(a => a.ModifiedDate).ToList(); break;

                        case "ascending": StudyResource.RecommendedEbookInfo = BookInfoList.OrderBy(a => a.Name).ToList(); break;

                        case "descending": StudyResource.RecommendedEbookInfo = BookInfoList.OrderByDescending(a => a.Name).ToList(); break;
                        }

                        switch (Sorting)
                        {
                        case "all": StudyResource.ModuleMaterials = SRInfoList.OrderByDescending(a => a.ModifiedDate).ToList(); break;

                        case "ascending": StudyResource.ModuleMaterials = SRInfoList.OrderBy(a => a.Name).ToList(); break;

                        case "descending": StudyResource.ModuleMaterials = SRInfoList.OrderByDescending(a => a.Name).ToList(); break;
                        }

                        StudyResource.StudyResourceInfo.Reference = studyResourceInfoList.Reference;
                        return StudyResource;
                    }
                    catch (Exception)
                    {
                        return StudyResource;
                    }
                }
            }));
        }
コード例 #21
0
        public Task <List <StudentTimeTable> > GetStudentTimeTable(int userID, int batchID, string date)
        {
            return(Task.Run(() =>
            {
                DateTime dateTime = DateTime.Now;
                using (MIUEntities db = new MIUEntities())
                {
                    List <LecturerTimeTable> timeTables = new List <LecturerTimeTable>();
                    List <StudentTimeTable> StudentTimeTables = new List <StudentTimeTable>();
                    CommonDAL commonDAL = new CommonDAL();
                    AttRateAndPercent attRateAndPercent = commonDAL.GetAttRateAndPercent(batchID, userID);
                    if (date != "\"\"" && !String.IsNullOrEmpty(date))
                    {
                        dateTime = Convert.ToDateTime(date);
                    }
                    if (attRateAndPercent.CurrentTermId != 0)
                    {
                        //timeTables = (from p in db.vProgramPlans
                        //              join u in db.Users on p.LectureID equals u.ID
                        //              join b in db.Batches on p.BatchID equals b.ID
                        //              join m in db.Modules on p.ModuleID equals m.ID
                        //              join c in db.Courses on b.CourseID equals c.ID
                        //              join t in db.TimeTableDetails on p.TermDetailID equals t.TermDetailID
                        //              where b.ID == batchID  && DbFunctions.TruncateTime(t.Date) == dateTime.Date
                        //              select new LecturerTimeTable
                        //              {
                        //                  LecturerID = u.ID,
                        //                  LoginName = u.LoginName,
                        //                  FullName = u.FullName,
                        //                  ProfilePicture = u.ProfilePicture,
                        //                  ProfilePicture2 = u.ProfilePicture2,
                        //                  CourseName = c.CourseName,
                        //                  ModuleCode = m.ModuleCode,
                        //                  ModuleName = m.ModuleName,
                        //                  StartTime = t.StartTime,
                        //                  EndTime = t.EndTime,
                        //                  TimeTableDate = t.Date
                        //              }).ToList();

                        StudentTimeTables = (from td in db.TimeTableDetails
                                             join ts in db.TimeSettings on td.TimeSettingID equals ts.ID
                                             join trd in db.TermDetails on td.TermDetailID equals trd.ID
                                             join m in db.Modules on trd.ModuleID equals m.ID
                                             join u in db.Users on trd.LectureID equals u.ID
                                             join t in db.Attendances
                                             //.Where(t => t.TermID == attRateAndPercent.CurrentTermId && t.StudentID == userID)
                                             on td.ID equals t.TimeTableDetailID
                                             where t.StudentID == userID
                                             //td.TermID == attRateAndPercent.CurrentTermId
                                             //&&
                                             //td.TermDetailID == t.TermDetailID
                                             //&& t.TermID == attRateAndPercent.CurrentTermId
                                             &&
                                             DbFunctions.TruncateTime(td.Date) == dateTime.Date
                                             orderby td.ID
                                             select new StudentTimeTable
                        {
                            TimeTableDetailID = td.ID,
                            Section = ts.Section,
                            StartTime = td.StartTime.ToString(),
                            EndTime = td.EndTime.ToString(),
                            TimeTableDate = td.Date,
                            LectureID = trd.LectureID,
                            LectureName = u.FullName,
                            ProfilePicture = u.ProfilePicture,
                            ModuleID = m.ID,
                            ModuleName = m.ModuleName,
                            IsAttending = t.IsAttending,
                            Attendance = t.IsAttending == true ? "Attended" : "Missed"
                        }).ToList();
                    }
                    //string strnow = DateTime.Now.ToString("hh:mm tt", CultureInfo.InvariantCulture);
                    //DateTime now = DateTime.ParseExact(strnow, "hh:mm tt", CultureInfo.InvariantCulture);
                    foreach (var data in StudentTimeTables)
                    {
                        data.ProfilePicture = MIUFileServer.GetFileUrl("ProfileImages", data.ProfilePicture);
                        if (data.TimeTableDate.Value.Date > DateTime.Now.Date)
                        {
                            data.Attendance = "";
                        }
                        else if (data.TimeTableDate.Value.Date == DateTime.Now.Date)
                        {
                            TimeSpan start;
                            TimeSpan end;
                            TimeSpan now = DateTime.Now.TimeOfDay;

                            if (data.StartTime.Contains("PM"))
                            {
                                string starttime = data.StartTime.Replace("PM", "");

                                string[] startStr = starttime.Split(':');
                                startStr[0] = (int.Parse(startStr[0]) + 12).ToString();
                                start = new TimeSpan(int.Parse(startStr[0]), int.Parse(startStr[1]), 0);
                            }
                            else
                            {
                                string starttime = data.StartTime.Replace("AM", "");
                                string[] startStr = starttime.Split(':');
                                startStr[0] = (int.Parse(startStr[0])).ToString();
                                start = new TimeSpan(int.Parse(startStr[0]), int.Parse(startStr[1]), 0);
                            }

                            if (data.EndTime.Contains("PM"))
                            {
                                string endtime = data.EndTime.Replace("PM", "");

                                string[] endStr = endtime.Split(':');
                                endStr[0] = (int.Parse(endStr[0]) + 12).ToString();
                                end = new TimeSpan(int.Parse(endStr[0]), int.Parse(endStr[1]), 0);
                            }
                            else
                            {
                                string endtime = data.EndTime.Replace("AM", "");
                                string[] endStr = endtime.Split(':');
                                endStr[0] = (int.Parse(endStr[0])).ToString();
                                end = new TimeSpan(int.Parse(endStr[0]), int.Parse(endStr[1]), 0);
                            }

                            if ((now < start) && (now < end))
                            {
                                data.Attendance = "";
                            }
                        }
                        //string strstart = DateTime.Now.ToString("dd-MMM-yy") + " " + data.StartTime.ToString();
                        //string strend = DateTime.Now.ToString("dd-MMM-yy") + " " + data.EndTime.ToString();
                        //DateTime end = DateTime.ParseExact(strend, "hh:mm:ss tt", CultureInfo.InvariantCulture);
                        //DateTime start = DateTime.ParseExact(strstart, "hh:mm:ss tt", CultureInfo.InvariantCulture);


                        //if (DbFunctions.TruncateTime(data.TimeTableDate) == DateTime.Now.Date && start >= now && end <= now)
                        //{
                        //    data.Attendance = "Attending";
                        //}
                        //else if((DbFunctions.TruncateTime(data.TimeTableDate) == DateTime.Now.Date && end > now) || data.TimeTableDate > DateTime.Now)
                        //{
                        //    data.Attendance = "";
                        //}
                    }

                    return StudentTimeTables;
                }
            }));
        }
コード例 #22
0
        public Task <JsonResponse> EditProfile(EditProfile EditProfile)
        {
            return(Task.Run(() =>
            {
                using (MIUEntities db = new MIUEntities())
                {
                    try
                    {
                        User user = db.Users.Where(x => x.ID == EditProfile.ID).SingleOrDefault();
                        List <User> userList = db.Users.Where(x => x.IsDelete != true && x.EmailAccount == EditProfile.EmailAccount).ToList();

                        var list = userList.ToList();

                        var emailExists = userList.Where(x => x.ID != EditProfile.ID).ToList();

                        if (user == null)
                        {
                            return new JsonResponse()
                            {
                                Flag = true, Message = "User is not found"
                            };
                        }
                        else if (user != null && emailExists.Count() > 0)
                        {
                            return new JsonResponse()
                            {
                                Flag = true, Message = "Email already exists"
                            };
                        }
                        else
                        {
                            string ImageName = "";

                            if (!String.IsNullOrEmpty(EditProfile.FileName) && EditProfile.FileName != "\"\"" && EditProfile.FileName != "")
                            {
                                Guid guid = Guid.NewGuid();
                                ImageName = guid.ToString() + "_" + Path.GetFileName(EditProfile.FileName);
                                user.ProfilePicture = ImageName;

                                if (!string.IsNullOrEmpty(EditProfile.Base64Image) && EditProfile.Base64Image != "\"\"" && EditProfile.Base64Image != "")
                                {
                                    byte[] Base64Image = Convert.FromBase64String(EditProfile.Base64Image);
                                    MIUFileServer.SaveToFileServer("ProfileImages", ImageName, Base64Image);
                                }
                            }
                            //user.ID = EditProfile.ID;
                            //user.FullName = EditProfile.FullName;
                            //user.Address = EditProfile.Address;
                            //user.DOB = EditProfile.DOB.Date;
                            user.EmailAccount = EditProfile.EmailAccount;
                            user.ContactNumber = EditProfile.ContactNumber;
                            user.MobilePhoneNumber = EditProfile.ContactNumber;
                            user.ModifiedBy = EditProfile.ModifiedBy;
                            user.ModifiedDate = EditProfile.ModifiedDate;
                            user.OrderDatetime = DateTime.Now;

                            AspNetUser aspNetUser = db.AspNetUsers.Where(x => x.UserName == user.LoginName).SingleOrDefault();
                            aspNetUser.Email = EditProfile.EmailAccount;

                            db.SaveChanges();
                            return new JsonResponse()
                            {
                                Flag = true, Message = "Successfully Updated"
                            };
                        }
                    }
                    catch (Exception ex)
                    {
                        return new JsonResponse()
                        {
                            Flag = false, Message = ex.Message
                        };
                    }
                }
            }));
        }