/// <summary>
        /// 取消工作任务
        /// </summary>
        /// <param name="taskId">工作任务Id</param>
        /// <param name="season">取消工作任务原因</param>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public bool Cancel(int taskId, string season, UserModel currentUser)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                //var entity = dbContext.WorkTasks.FirstOrDefault(it => it.Id == taskId);
                //if (entity == null)
                //{
                //    Log.Error(string.Format("任务无效, 任务ID: {0}", taskId));
                //    throw new InvalidOperationException("任务无效");
                //}

                //if (entity.Status != (int) WorkTaskStatus.Created)
                //{
                //    Log.Error("任务已开始,不能取消。");
                //    throw new InvalidOperationException("任务已开始,不能取消。");
                //}

                //entity.Status = (int)WorkTaskStatus.Canceled;

                //AddHistory(dbContext, currentUser.Id, taskId, WorkTaskStatus.Canceled,
                //    string.Format("{0}取消了任务,原因: {1}。", currentUser.EnglishName, season)); //记录日志

                //AddNotification(dbContext, entity.ToModel(), currentUser, season); //推送消息

                //dbContext.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 2
0
        public ListResult <MeetingRoomModel> List(int pageNo, int pageSize, SortModel sort, FilterModel filter)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var list = dbContext.MeetingRooms.AsEnumerable();

                //if (sort != null)
                //{

                //}

                var count = list.Count();

                list = list.Skip((pageNo - 1) * pageSize).Take(pageSize).ToList();

                ListResult <MeetingRoomModel> result = new ListResult <MeetingRoomModel>();
                result.Data = new List <MeetingRoomModel>();
                list.ToList().ForEach(item =>
                {
                    result.Data.Add(item.ToModel());
                });

                result.Total = count;
                return(result);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加工作任务评论
        /// </summary>
        /// <param name="user">评论人</param>
        /// <param name="taskId">工作任务</param>
        /// <param name="comment">评论</param>
        public bool AddComment(UserModel user, int taskId, string comment)
        {
            if (taskId <= 0 || string.IsNullOrEmpty(comment))
            {
                Log.Error("无效的评论。");
                throw new InvalidOperationException("无效的评论。 ");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                var entity = new WorkTaskComment()
                {
                    Comment     = comment,
                    UserId      = user.Id,
                    TaskId      = taskId,
                    CreatedTime = DateTime.Now
                };

                dbContext.WorkTaskComments.Add(entity); //添加评论

                dbContext.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取用户待处理的申请单
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="status">申请单状态</param>
        /// <returns>审批任务列表</returns>
        public List <OrderModel> GetPendingOrdersByUserId(int userId, OrderStatus?status = null)
        {
            if (status == null)
            {
                status = OrderStatus.Invalid;
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                var pendingOrders = new List <OrderModel>();

                dbContext.Orders.Where(
                    it => status == OrderStatus.Invalid || (!it.Status.HasValue && status == OrderStatus.Apply) || (int)status == it.Status)
                .ToList()
                .ForEach(it =>
                {
                    var order = it.ToModel();

                    //待处理申请单: 申请 || 领导审批中 || 行政财务审阅中 && 下一步审批人为当前登录用户
                    if (pendingOrders.Any(o => o.OrderNo == order.OrderNo) == false &&     //过滤批量申请单
                        (order.IsApproveStatus() || order.IsReviewStatus()) &&
                        it.NextAudit.HasValue && it.NextAudit.Value == userId)
                    {
                        DoFill(dbContext, order);
                        pendingOrders.Add(order);
                    }
                });

                return(pendingOrders);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 填充user关联信息
        /// </summary>
        /// <param name="dbContext">数据库上下文</param>
        /// <param name="user">用户model</param>
        public static void FillRelatedDetail(MissionskyOAEntities dbContext, UserModel user)
        {
            if (dbContext == null)
            {
                throw new NullReferenceException("Invalid db context when fill user detail.");
            }

            if (user == null)
            {
                throw new NullReferenceException("Invalid user model when fill user detail.");
            }

            //汇总信息
            user.VacationSummary = (new AttendanceSummaryService()).GetAttendanceSummariesByUserId(dbContext, user.Id);

            //部门
            var dept = dbContext.Departments.FirstOrDefault(it => it.Id == user.DeptId);

            user.DeptName = dept == null ? string.Empty : dept.Name;

            //角色
            var userrole = dbContext.UserRoles.FirstOrDefault(it => it.UserId == user.Id);

            user.RoleName = userrole == null || userrole.Role == null ? string.Empty : userrole.Role.Name;
            if (userrole != null)
            {
                user.Role = userrole.RoleId;
            }

            //项目
            var project = dbContext.Projects.FirstOrDefault(it => it.Id == user.ProjectId);

            user.ProjectName = project == null ? string.Empty : project.Name;
        }
        /// <summary>
        /// 添加工作流流骤
        /// </summary>
        /// <param name="model">工作流步骤</param>
        /// <returns>工作流步骤id</returns>
        public int AddWorkflowStep(WorkflowStepModel model)
        {
            if (model == null)
            {
                Log.Error("工作流步骤无效。");
                throw new InvalidOperationException("工作流步骤无效。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                ValidWorkflowStep(dbContext, model);

                //添加工作流
                var entity = model.ToEntity();
                entity.CreatedTime = DateTime.Now;

                //不是领导审批,不需要设置时长
                if (model.Type != WorkflowStepType.LeaderApprove)
                {
                    entity.MinTimes = 0.0;
                    entity.MaxTimes = 0.0;
                }

                dbContext.WorkflowSteps.Add(entity);
                dbContext.SaveChanges();

                //更新流程步骤下一步
                model.Id = entity.Id;
                UpdateNextStep(dbContext, model);

                return(model.Id);
            }
        }
        /// <summary>
        /// 更新流程步骤下一步
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="nextStep"></param>
        /// <param name="isSaved"></param>
        private void UpdateNextStep(MissionskyOAEntities dbContext, WorkflowStepModel nextStep, bool isSaved = true)
        {
            if (nextStep.PrevStep.HasValue && nextStep.PrevStep.Value > 0)
            {
                var prevStep = dbContext.WorkflowSteps.FirstOrDefault(
                    it => it.FlowId == nextStep.FlowId && it.Id == nextStep.PrevStep.Value);

                if (prevStep == null)
                {
                    Log.Error("流程步骤上一步不存在。");
                    throw new KeyNotFoundException("流程步骤上一步不存在。");
                }

                if (prevStep.NextStep.HasValue && prevStep.NextStep.Value > 0 && prevStep.NextStep.Value != nextStep.Id)
                {
                    Log.Error("流程步骤上一步不存在。");
                    throw new KeyNotFoundException("流程步骤上一步不存在。");
                }

                prevStep.NextStep = nextStep.Id;

                if (isSaved)
                {
                    dbContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 8
0
        public static BookModel ToModel(this Book entity)
        {
            var model = new BookModel()
            {
                Id          = entity.Id,
                Type        = entity.Type,
                Author      = entity.Author,
                Desc        = entity.Desc,
                Name        = entity.Name,
                ISBN        = entity.ISBN,
                BarCode     = entity.BarCode,
                Donor       = entity.Donor,
                Reader      = entity.Reader,
                Source      = entity.Source.HasValue ? (BookSource)entity.Source.Value : BookSource.None,
                Status      = entity.Status.HasValue ? (BookStatus)entity.Status.Value : BookStatus.None,
                CreatedDate = entity.CreatedDate
            };

            using (var dbContext = new MissionskyOAEntities())
            {
                //Get english name
                var userEntity = dbContext.Users.FirstOrDefault(it => it.Id == entity.Donor);
                if (userEntity != null)
                {
                    model.DonorName = userEntity.EnglishName;
                }
            }

            return(model);
        }
 /// <summary>
 /// 删除属性
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool Remove(int id)
 {
     using (var dbContext = new MissionskyOAEntities())
     {
         var entity = dbContext.AssetAttributes.Where(it => it.Id == id).FirstOrDefault();
         if (entity != null)
         {
             var assetInfoCount = dbContext.AssetInfoes.Where(it => it.AttributeId == entity.Id).Count();
             if (assetInfoCount > 0)
             {
                 throw new Exception("该属性已经被资产使用,不能删除.");
             }
             if (entity.AssetTypeAttributes != null && entity.AssetTypeAttributes.Count > 0)
             {
                 //删除类型关联的该属性数据
                 var asetTypeAttributeEntitys = entity.AssetTypeAttributes.ToList();
                 for (int i = asetTypeAttributeEntitys.Count - 1; i >= 0; i--)
                 {
                     dbContext.AssetTypeAttributes.Remove(asetTypeAttributeEntitys[i]);
                 }
             }
             dbContext.AssetAttributes.Remove(entity);
         }
         dbContext.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 转移图书
        /// </summary>
        /// <param name="model">借阅信息</param>
        /// <param name="userId">当前借阅用户</param>
        /// <returns>true or false</returns>
        public bool Transfer(BorrowBookModel model, int userId)
        {
            if (model == null)
            {
                throw new InvalidOperationException("图书借阅信息无效。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                //当前用户的借阅信息失效
                var current =
                    dbContext.BookBorrows.FirstOrDefault(
                        it =>
                        it.BookId == model.BookId && it.UserId == userId &&
                        it.Status == (int)UserBorrowStatus.Borrowing);

                if (current != null)
                {
                    current.Status = (int)UserBorrowStatus.Returned;
                }

                //转移图书到其它用户
                if (model.Reader.HasValue && DoBorrow(dbContext, model, model.Reader.Value))
                {
                    dbContext.SaveChanges();
                }
            }

            return(true);
        }
Ejemplo n.º 11
0
        public IPagedList <BookISBNGroupModel> GetBookListByISBNGroup(SearchBookModel search, int pageIndex, int pageSize)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var query      = DoSearch(dbContext, search); //查询
                var groupQuery = query.GroupBy(x => x.ISBN).Select(group =>
                                                                   new
                {
                    ISBN  = group.Key,
                    books = group.Where(it => it.Id != null)
                });

                List <BookISBNGroupModel> bookGroupList = new List <BookISBNGroupModel>();

                groupQuery.ToList().ForEach(item =>
                {
                    BookISBNGroupModel temp = new BookISBNGroupModel()
                    {
                        books = new List <BookModel>()
                    };
                    temp.ISBN = item.ISBN;
                    item.books.ToList().ForEach(i =>
                    {
                        temp.books.Add(DoFill(i.ToModel()));
                    });
                    temp.amount = item.books.ToList().Count;
                    temp.books  = temp.books.OrderByDescending(it => it.Rating.AverageRating).ToList();
                    bookGroupList.Add(temp);
                });
                return(new PagedList <BookISBNGroupModel>(bookGroupList, pageIndex, pageSize));
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取用户已借阅的图书
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns>图书列表</returns>
        public IList <BookModel> GetUserBorrowedBooks(int userId)
        {
            if (userId < 1)
            {
                throw new InvalidOperationException("用户ID无效。");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                var list = new List <BookModel>();

                var userBorrows = _borrowService.GetUserBorrowHistory(userId); //用户借阅记录

                if (userBorrows != null)
                {
                    userBorrows.ToList().ForEach(borrow =>
                    {
                        if (!list.Exists(it => it.Id == borrow.BookId)) //消除重复
                        {
                            var book = dbContext.Books.FirstOrDefault(entity => entity.Id == borrow.BookId);

                            if (book != null)
                            {
                                list.Add(DoFill(book.ToModel(), userId));
                            }
                        }
                    });
                }

                return(list);
            }
        }
        /// <summary>
        /// 获取申请单流程
        /// </summary>
        /// <param name="dbContext">数据库上下文对象</param>
        /// <param name="order">申请单</param>
        /// <param name="curUser">当前用户</param>
        /// <param name="operation">操作</param>
        /// <returns>流程对象</returns>
        private WorkflowModel GetWorkflow(MissionskyOAEntities dbContext, OrderModel order, UserModel curUser, OperateOrderModel operation)
        {
            var searchWorkflow = new SearchWorkflowModel();

            if (operation.Operation == WorkflowOperation.Apply) //申请
            {
                //获取流程Id
                searchWorkflow.WorkflowId = MatchWorkflow(dbContext, order, curUser); //匹配当前用户满足条件的申请流程
            }
            else
            {
                if (!order.WorkflowId.HasValue)
                {
                    Log.Error("无效的申请单流程。");
                    throw new InvalidOperationException("无效的申请单流程。");
                }

                searchWorkflow.WorkflowId = order.WorkflowId.Value;
            }

            var workflow = _workflowService.GetWorkflowDetail(dbContext, searchWorkflow.WorkflowId); //流程

            if (workflow == null)
            {
                Log.Error("找不到申请流程。");
                throw new KeyNotFoundException("找不到申请流程。");
            }

            return(workflow);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 转移(指派)工作任务
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="executor">执行人</param>
        /// <param name="currentUser"></param>
        /// <param name="comment">备注信息</param>
        /// <returns></returns>
        public bool Transfer(int taskId, int executor, UserModel currentUser, string comment = null)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                //var entity = dbContext.WorkTasks.FirstOrDefault(it => it.Id == taskId);
                //if (entity == null)
                //{
                //    Log.Error(string.Format("任务无效, 任务ID: {0}", taskId));
                //    throw new InvalidOperationException("任务无效");
                //}

                //entity.Executor = executor; //更改执行人
                //entity.Status = (int) WorkTaskStatus.Transfered;

                //AddHistory(dbContext, currentUser.Id, taskId, WorkTaskStatus.Transfered,
                //    string.Format("{0}更改了执行人,备注: {1}。", currentUser.EnglishName, comment)); //记录日志

                ////添加推送消息
                //AddNotification(dbContext, entity.ToModel(), currentUser);

                //dbContext.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 根据步骤Id获取详细
        /// </summary>
        /// <param name="stepId">步骤Id</param>
        /// <returns>流程步骤详细</returns>
        public WorkflowStepModel GetStepDetailById(int stepId)
        {
            if (stepId < 1)
            {
                throw new KeyNotFoundException("Invalid workflow");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                var step = dbContext.WorkflowSteps.FirstOrDefault(it => it.Id == stepId); //获取流程步取

                if (step == null)
                {
                    Log.Error(string.Format("无效的工作流步骤。步骤id: {0}", stepId));
                    throw new KeyNotFoundException(string.Format("无效的工作流步骤。步骤id: {0}", stepId));
                }

                var workflow = dbContext.Workflows.FirstOrDefault(it => it.Id == step.FlowId);
                if (workflow == null)
                {
                    Log.Error(string.Format("无效的工作流。流程id: {0}", step.FlowId));
                    throw new KeyNotFoundException(string.Format("无效的工作流。流程id: {0}", step.FlowId));
                }

                var model = step.ToModel();
                model.FlowName = workflow.Name;

                return(step.ToModel());
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 显示所有加班单
        /// </summary>
        /// <returns>所有加班单分页信息</returns>
        public IPagedList <OrderModel> MyOvertimeList(UserModel model, int pageIndex, int pageSize)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                List <OrderModel> result = new List <OrderModel>();

                var orders =
                    dbContext.Orders.Where(
                        it =>
                        ((it.UserId == model.Id || it.ApplyUserId == model.Id) &&     //查询用户申请的或者用户自己的
                         it.OrderType == (int)OrderType.Overtime)
                        ).OrderByDescending(item => item.CreatedTime);

                orders.ToList().ForEach(item =>
                {
                    var order = item.ToModel();
                    if (result.Any(it => it.OrderNo == order.OrderNo) == false) //过滤批量申请,重复的申请单
                    {
                        OrderService.DoFill(dbContext, order);
                        result.Add(order);
                    }
                });

                return(new PagedList <OrderModel>(result, pageIndex, pageSize));
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 删除工作流
        /// </summary>
        /// <param name="id">工作流id</param>
        /// <returns>是否删除成功</returns>
        public bool DeleteWorkflow(int id)
        {
            using (var dbcontext = new MissionskyOAEntities())
            {
                var isUsed = dbcontext.Orders.Any(it => it.WorkflowId == id);

                if (isUsed)
                {
                    Log.Error("流程已被使用,不能删除。");
                    throw new KeyNotFoundException("流程已被使用,不能删除。");
                }

                var entity = dbcontext.Workflows.FirstOrDefault(it => it.Id == id);

                if (entity == null)
                {
                    Log.Error("找不到工作流。");
                    throw new KeyNotFoundException("找不到工作流。");
                }

                //删除流程步骤
                if (entity.WorkflowSteps != null)
                {
                    entity.WorkflowSteps.ToList().ForEach(it => dbcontext.WorkflowSteps.Remove(it));
                }

                dbcontext.Workflows.Remove(entity);
                dbcontext.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 18
0
        public static OrderDetModel ToModel(this OrderDet entity)
        {
            var model = new OrderDetModel()
            {
                Id        = entity.Id,
                OrderId   = entity.OrderId,
                StartDate = entity.StartDate,
                StartTime = entity.StartTime,
                EndDate   = entity.EndDate,
                EndTime   = entity.EndTime,
                IOHours   = entity.IOHours,

                Description  = entity.Description,
                Audit        = entity.Audit ?? string.Empty,
                InformLeader = entity.InformLeader ?? false,
                WorkTransfer = entity.WorkTransfer ?? false,
                Recipient    = entity.Recipient.HasValue ? entity.Recipient.Value : 0,
            };

            using (var dbContext = new MissionskyOAEntities())
            {
                UserService userServer = new UserService();
                if (entity.Recipient != null)
                {
                    var RecipientUser = userServer.GetUserDetail(entity.Recipient.Value);
                    model.RecipientName = RecipientUser == null ? string.Empty : RecipientUser.EnglishName;
                }
            }

            model.StartDate = Convert.ToDateTime(entity.StartDate.ToShortDateString() + " " + entity.StartTime.ToString());
            model.EndDate   = Convert.ToDateTime(entity.EndDate.ToShortDateString() + " " + entity.EndTime.ToString());
            return(model);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 删除工作流步骤
        /// </summary>
        /// <param name="id">工作流步骤id</param>
        /// <returns>是否删除成功</returns>
        public bool DeleteWorkflowStep(int id)
        {
            using (var dbcontext = new MissionskyOAEntities())
            {
                var isUsed = dbcontext.Orders.Any(it => it.NextStep.HasValue && it.NextStep.Value == id);

                if (isUsed)
                {
                    Log.Error("已被使用,不能删除步骤。");
                    throw new KeyNotFoundException("已被使用,不能删除步骤。");
                }

                var entity = dbcontext.WorkflowSteps.FirstOrDefault(it => it.Id == id);

                if (entity == null)
                {
                    Log.Error("找不到工作流步骤。");
                    throw new KeyNotFoundException("找不到工作流步骤。");
                }

                dbcontext.WorkflowSteps.Remove(entity);
                dbcontext.SaveChanges();

                return(true);
            }
        }
Ejemplo n.º 20
0
        public static ProjectModel ToModel(this Project entity)
        {
            var model = new ProjectModel()
            {
                Id             = entity.Id,
                ProjectId      = entity.Id,
                Name           = entity.Name,
                CreatedTime    = entity.CreatedTime,
                CreateUserName = entity.CreateUserName,
                ProjectBegin   = entity.ProjectBegin,
                ProjectEnd     = entity.ProjectEnd,
                ProjectNo      = entity.ProjectNo,
                Status         = entity.Status,
                ProjectManager = entity.ProjectManager
            };

            using (var dbContext = new MissionskyOAEntities())
            {
                //Get english name
                var userEntity = dbContext.Users.FirstOrDefault(it => it.Id == entity.ProjectManager);
                if (userEntity != null)
                {
                    model.ProjectManagerName = userEntity.EnglishName;
                }
            }
            return(model);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 获取当前申请单号
        ///
        /// 生成申请单号
        ///
        /// </summary>
        /// <param name="dbContext"></param>
        /// <returns>申请单号</returns>
        public int GenerateOrderNo(MissionskyOAEntities dbContext)
        {
            // 1、
            int currentApplyOrderId = 0;

            /*
             *
             *  涉及到EntityFramework.dll的DbContext的使用
             *
             *  SqlQuery<TElement>(string sql,params object[] parameters) 返回的是一个 DbRawSqlQuery<TElement>类型对象
             *
             *
             * **/
            // 2、获取当前Order表中OrderNo的最大值,然后再+1,就是新申请单的OrderNo
            var data = dbContext.Database.SqlQuery <int>(GENERATE_ORDER_NO);

            var test = data.ToList();

            // 3、
            if (data != null)
            {
                currentApplyOrderId = Math.Abs(data.FirstOrDefault());
            }

            // 4、
            return(currentApplyOrderId);
        }
        private void GetComments(MissionskyOAEntities dbContext, IList <BookCommentModel> comments, int bookId, BookRatingModel rating = null)
        {
            var entities =
                dbContext.BookComments.Where(it => it.BookId == bookId).OrderByDescending(it => it.CreatedDate).ToList();

            entities.ForEach(entity =>
            {
                var model = entity.ToModel();

                //评价用户
                var user       = dbContext.Users.FirstOrDefault(it => it.Id == model.UserId);
                model.UserName = (user == null ? string.Empty : user.EnglishName);

                comments.Add(model); //评价

                #region 评分汇总
                if (rating != null)
                {
                    if (entity.Rating.HasValue)
                    {
                        rating.Count++;
                        rating.TotalRating += entity.Rating.Value; //记算总分
                    }

                    if (rating.Count > 0)
                    {
                        rating.AverageRating = ((double)rating.TotalRating / rating.Count).Round(); //记算平均分
                    }
                }
                #endregion
            });
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 获取用户待处理的申请单数量
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public PendingOrderCountModel CountPendingOrders(int userId)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var model  = new PendingOrderCountModel();
                var orders = new List <int>();

                dbContext.Orders.ToList().ForEach(it =>
                {
                    var order = it.ToModel();

                    //待处理申请单: 申请 || 领导审批中 || 行政财务审阅中 && 下一步审批人为当前登录用户
                    if (orders.Any(o => o == it.OrderNo) == false && //过滤批量申请单
                        (order.IsApproveStatus() || order.IsReviewStatus()) &&
                        it.NextAudit.HasValue && it.NextAudit.Value == userId)
                    {
                        if (order.IsAskLeave()) //汇总请假
                        {
                            model.AskLeave++;
                        }

                        if (order.IsOvertime()) //汇总加班
                        {
                            model.Overtime++;
                        }
                    }

                    orders.Add(it.OrderNo);
                });

                return(model);
            }
        }
        /// <summary>
        /// 汇总图书评分
        /// </summary>
        /// <param name="bookId">图书id</param>
        /// <returns>图书评分</returns>
        public BookRatingModel CountBookRading(int bookId)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var rading = new BookRatingModel();

                var entities =
                    dbContext.BookComments.Where(it => it.BookId == bookId).ToList();

                entities.ForEach(it =>
                {
                    if (it.Rating.HasValue)
                    {
                        rading.Count++;
                        rading.TotalRating += it.Rating.Value;
                    }

                    if (rading.Count > 0)
                    {
                        rading.AverageRating = ((double)rading.TotalRating / rading.Count).Round();
                    }
                });

                return(rading);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 根据日期时间返回会议预定记录
        /// </summary>
        /// <returns>会议预定记录</returns>
        public List <MeetingDateGroupModel> GetMeetingListByDateTime(MeetingSearchModel model)
        {
            using (var dbcontext = new MissionskyOAEntities())
            {
                //查询
                var entity = dbcontext.MeetingCalendars.Where(it => it.MeetingRoomId == model.MeetingRoomId && it.StartDate >= model.StartDate.Date && it.StartDate <= model.EndDate.Date && it.Status == 1).GroupBy(x => x.StartDate).AsEnumerable().Select(group =>
                                                                                                                                                                                                                                                             new
                {
                    startdate = group.Key,
                    Meetings  = group.Where(it => it.Id != null).OrderBy(c => c.StartTime)
                });

                if (entity == null)
                {
                    throw new Exception("此日期段内无会议信息");
                }
                //根据日期group返回会议记录
                List <MeetingDateGroupModel> meetingList = new List <MeetingDateGroupModel>();
                entity.ToList().ForEach(item =>
                {
                    MeetingDateGroupModel temp = new MeetingDateGroupModel()
                    {
                        meetings = new List <MeetingCalendarModel>()
                    };
                    temp.startDate = item.startdate;
                    item.Meetings.ToList().ForEach(i =>
                    {
                        temp.meetings.Add(i.ToModel());
                    });
                    meetingList.Add(temp);
                });
                return(meetingList);
            }
        }
 /// <summary>
 /// 获取指定ID图书的评价
 /// </summary>
 /// <param name="bookId">图书ID</param>
 /// <param name="rating">评价汇总(输出)</param>
 /// <returns>评价列表</returns>
 public IList <BookCommentModel> GetBookCommentList(int bookId, BookRatingModel rating = null)
 {
     using (var dbContext = new MissionskyOAEntities())
     {
         return(GetBookCommentList(dbContext, bookId, rating));
     }
 }
Ejemplo n.º 27
0
 /// <summary>
 /// 获取指定ID工作任务评论
 /// </summary>
 /// <param name="taskId">任务ID</param>
 /// <returns>工作任务评论</returns>
 public IList <WorkTaskCommentModel> GetWorkTaskCommentList(int taskId)
 {
     using (var dbContext = new MissionskyOAEntities())
     {
         return(GetWorkTaskCommentList(dbContext, taskId));
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        /// 根据id查询流程详细
        /// </summary>
        /// <param name="flowId">流程Id</param>
        /// <returns>流程详细</returns>
        public WorkflowModel GetWorkflowDetail(int flowId)
        {
            if (flowId < 0)
            {
                throw new KeyNotFoundException("Invalid workflow id for query detail.");
            }

            using (var dbContext = new MissionskyOAEntities())
            {
                var entity = dbContext.Workflows.Where(it => it.Id == flowId).FirstOrDefault();

                if (entity == null)
                {
                    throw new KeyNotFoundException("Cannot query the workflow detail by id.");
                }

                if (entity.WorkflowSteps == null)
                {
                    var steps = dbContext.WorkflowSteps.Where(it => it.FlowId == entity.Id).OrderBy(it => it.Id);
                    entity.WorkflowSteps = steps.ToList();
                }

                return(entity.ToModel());
            }
        }
Ejemplo n.º 29
0
        public static AnnouncementModel ToModel(this Announcement entity)
        {
            var model = new AnnouncementModel()
            {
                Id                  = entity.Id,
                Type                = (AnnouncementType)entity.Type,
                Title               = entity.Title,
                Content             = entity.Content,
                ApplyUserId         = entity.ApplyUserId,
                EffectiveDays       = entity.EffectiveDays,
                CreateUserId        = entity.CreateUserId,
                CreatedTime         = entity.CreatedTime,
                Status              = (AnnouncementStatus)entity.Status,
                AuditReason         = entity.AuditReason,
                RefAssetInventoryId = entity.RefAssetInventoryId
            };

            using (var dbContext = new MissionskyOAEntities())
            {
                //Get english name
                var userEntityForApplyUser = dbContext.Users.FirstOrDefault(it => it.Id == entity.ApplyUserId);
                if (userEntityForApplyUser != null)
                {
                    model.ApplyUserName = userEntityForApplyUser.EnglishName;
                }

                var userEntity = dbContext.Users.FirstOrDefault(it => it.Id == entity.CreateUserId);
                if (userEntity != null)
                {
                    model.CreateUserName = userEntity.EnglishName;
                }
            }
            return(model);
        }
        /// </summary>
        /// 显示在有效期内的通告
        /// </summary>
        /// <returns>有效期内的通告信息</returns>
        public IPagedList <AnnouncementModel> AnnouncementList(int pageIndex, int pageSize)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                DateTime currentDate            = DateTime.Now.Date;
                List <AnnouncementModel> result = new List <AnnouncementModel>();

                var annocumentList = dbContext.Announcements.Where(it => it.Status == (int)AnnouncementStatus.AllowPublish).OrderByDescending(item => item.CreatedTime);

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

                annocumentList.ToList().ForEach(item =>
                {
                    if (item.CreatedTime.Value.AddDays((double)item.EffectiveDays) > currentDate)
                    {
                        result.Add(item.ToModel());
                    }
                });

                return(new PagedList <AnnouncementModel>(result, pageIndex, pageSize));
            }
        }