/// <summary>
        /// 建立學習圈 - [後臺管理API用]
        /// </summary>
        /// <returns></returns>
        public LearningCircle CreateLearningCircle(string name, string circleKey, string description, string token, DateTime startDate, DateTime endDate, int?orgId, string objective = null, int?section = null)
        {
            var db = _uow.DbContext;

            var checkDBEmpty = db.LearningCircle.FirstOrDefault(t => t.LearningOuterKey == circleKey && t.Name == name);

            if (checkDBEmpty != null)
            {
                return(checkDBEmpty);
            }
            var now          = DateTime.UtcNow;
            var tokenService = new TokenService();
            var creator      = tokenService.GetTokenInfo(token).Result;
            var entity       = new LearningCircle()
            {
                Created     = TimeData.Create(now),
                Deleted     = TimeData.Create(null),
                Updated     = TimeData.Create(null),
                CreateUser  = creator.MemberId,
                Description = description,
                Name        = name,
                Enable      = true,
                Visibility  = true,
                StartDate   = startDate.ToUniversalTime(),
                EndDate     = endDate.ToUniversalTime(),
                LCType      = 10,
                Objective   = objective
            };

            if (section.HasValue)
            {
                entity.Section = section.Value.ToString();
            }
            if (orgId.HasValue)
            {
                entity.OrgId = orgId.Value;
            }

            if (circleKey == null || circleKey == string.Empty)
            {
                circleKey = string.Format("{0}{1}", now.Ticks.ToString(), "course");
            }

            entity.LearningOuterKey = circleKey.ToLower();

            db.LearningCircle.Add(entity);
            db.SaveChanges();
            var memberInviteService = new MemberInviteService();
            var memerInviteInfo     = memberInviteService.CreateFromCreateLearningCircle(circleKey.ToLower());

            return(entity);
        }
Esempio n. 2
0
        /// <summary>
        /// 新增請假單 - 預先新增假單
        /// </summary>
        /// <param name="learningId"></param>
        /// <param name="isTeacher"></param>
        /// <param name="memberId"></param>
        /// <param name="leaveDateTime"></param>
        /// <param name="leaveCategoryId"></param>
        /// <param name="leaveStatus"></param>
        /// <param name="title"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        public Infrastructure.ViewModel.SignInLogViewModel Add(LearningCircle learningInfo, int memberId, Infrastructure.DataTransferObject.UploadFileModel uploadInfo, List <FileStorage> files, List <Stream> fileStreams)
        {
            var parentFolderId = string.Empty;

            var db             = _uow.DbContext;
            var connectionInfo = db.Members.Find(memberId);
            var memberAccount  = _uow.EntityRepository <Member>().GetFirst(x => x.Id == memberId);

            if (memberAccount == null)
            {
                return(null);
            }

            var _entity    = new AttendanceLeave();
            var _actEntity = new Activitys();

            lock (_lock)
            {
                DateTime dt    = DateTime.UtcNow;
                Guid     eveId = Guid.NewGuid();
                try
                {
                    var studentLeave = db.AttendanceLeave.Where(t => t.StudId == memberId).ToList();
                    var checkIsLeave = new AttendanceLeave();
                    if (studentLeave.FirstOrDefault() != null)
                    {
                        checkIsLeave = studentLeave.FirstOrDefault(t => t.LeaveDate.Date == uploadInfo.LeaveDate.Date && t.Status != "40" && t.LearningId == learningInfo.Id);
                    }
                    else
                    {
                        checkIsLeave = null;
                    }
                    if (checkIsLeave == null)
                    {
                        _entity.Content    = uploadInfo.Content;
                        _entity.CreateDate = dt;
                        _entity.Creator    = memberId;
                        _entity.EventId    = eveId;
                        _entity.LearningId = learningInfo.Id;
                        if (uploadInfo.LeaveDate.Hour == 0)
                        {
                            _entity.LeaveDate = uploadInfo.LeaveDate;
                        }
                        else
                        {
                            _entity.LeaveDate = uploadInfo.LeaveDate.ToUniversalTime();
                        }
                        _entity.LeaveType = uploadInfo.LeaveCategoryId;
                        _entity.Status    = QueryCondition.LeaveState.Review;
                        _entity.StudId    = memberId;
                        _entity.Subject   = uploadInfo.Title;
                        db.AttendanceLeave.Add(_entity);
                        _actEntity.Created     = Infrastructure.Property.TimeData.Create(dt);
                        _actEntity.Updated     = Infrastructure.Property.TimeData.Create(null);
                        _actEntity.Deleted     = Infrastructure.Property.TimeData.Create(null);
                        _actEntity.CreateUser  = memberId;
                        _actEntity.IsActivity  = false;
                        _actEntity.ModuleKey   = Utility.ParaCondition.ModuleType.Leave;
                        _actEntity.OuterKey    = eveId;
                        _actEntity.CardisShow  = false;
                        _actEntity.Publish_Utc = dt;
                        _actEntity.ToRoomId    = learningInfo.LearningOuterKey;
                        db.Activitys.Add(_actEntity);

                        //執行
                        db.SaveChanges();
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    return(null);

                    throw ex;
                }
            }


            var newFiles   = fileService.UploadFiles(memberId, files, fileStreams.ToArray());
            var _fileArray = new string[files.Count];

            if (files.Count > 0)
            {
                //建立檔案與請假單的關聯
                SetLeaveFileReferenceByFiles(_entity.Id, newFiles);
            }

            var result = new Infrastructure.ViewModel.SignInLogViewModel
            {
                EventId           = _entity.EventId,
                OuterKeySignInLog = new Dictionary <string, SignInLog>()
            };
            //db = new iThinkDB();
            var sqlSignInActivity = db.Activitys.Where(t => t.ToRoomId.ToLower() == uploadInfo.CircleKey.ToLower() && t.ModuleKey == Utility.ParaCondition.ModuleType.SignIn && t.CardisShow == true && t.StartDate.HasValue);

            foreach (var _act in sqlSignInActivity)
            {
                if (_act.ActivityDate != null)
                {
                    if (_act.ActivityDate.Value.ToLocalTime().Date == uploadInfo.LeaveDate.Date)
                    {
                        var mylog = signInLogService.GetSignInLog(Convert.ToInt32(_act.CreateUser.ToString()), _act.OuterKey, memberId);
                        if (mylog != null)
                        {
                            mylog.LeaveStatus = "20";
                            mylog.Mode        = 0;
                            mylog.Time        = DateTime.UtcNow;
                            var outerKey = Utility.OuterKeyHelper.GuidToPageToken(_act.OuterKey);
                            result.OuterKeySignInLog.Add(outerKey, mylog);
                        }
                    }
                }
            }
            return(result);
        }