public IActionResult AddStudentGroup(AddStudentGroupRequest request)
        {
            //宿舍id参数校验
            if (!request.StudentGroupId.HasValue)
            {
                //宿舍编号为空
                return(Failure(ResultCode.PARAM_IS_INVALLD));
            }
            //宿舍名参数校验
            if (string.IsNullOrEmpty(request.StudentGroupName))
            {
                //宿舍名为空
                return(Failure(ResultCode.PARAM_NOT_COMPLETE));
            }

            //判断宿舍id是否重复
            var studentgroup = _demoContext.DB.Queryable <Student_Group>().InSingle(request.StudentGroupId.Value);

            if (studentgroup != null)
            {
                //宿舍编号重复
                return(Failure(ResultCode.PARAM_NO_COMPLETE));
            }

            //判断宿舍名是否重复
            var studentGroupName = _demoContext.DB.Queryable <Student_Group>().InSingle(request.StudentGroupName);

            if (studentGroupName != null)
            {
                //宿舍名重复
                return(Failure(ResultCode.PARAM_NAME_COMPLETE));
            }

            Student_Group studentGroup = new Student_Group();

            studentGroup.StudentGroupId   = request.StudentGroupId.Value;
            studentGroup.StudentGroupName = request.StudentGroupName;
            studentGroup.IsDelete         = 0;

            int count = _demoContext.DB.Insertable(studentGroup).ExecuteReturnIdentity();

            //添加宿舍
            return(count > 0 ? Success() : Failure(ResultCode.SYSTEM_INNER_ERROR));
        }
        public JsonResult AcceptRequest(int id)
        {
            int mystdid = Convert.ToInt32(Session["StudentId"]);
            var Stdreq  = db.Student_Request.Where(p => p.Request_From_Id == id && p.Request_To_Id == mystdid).FirstOrDefault();

            db.Dispose();
            var std = new Student_Request()
            {
                ID = Stdreq.ID
            };

            db = new FYPEntities();
            db.Student_Request.Attach(std);

            std.Is_Active      = false;
            std.Is_Accepted    = true;
            std.Date_Accepeted = DateTime.Now;
            db.SaveChanges();
            db.Dispose();

            db = new FYPEntities();
            group grp = new group();

            grp.GroupName   = "Group " + Stdreq.Request_From_Id + " --" + Stdreq.Request_To_Id;
            grp.Is_Active   = true;
            grp.DateCreated = DateTime.Now;
            db.groups.Add(grp);
            db.SaveChanges();

            int grpid = grp.Id;

            var stdgrp = new Student_Group();

            stdgrp.Student_1_ID = Stdreq.Request_From_Id;
            stdgrp.Student_2_ID = Stdreq.Request_To_Id;
            stdgrp.Group_Id     = grpid;
            db.Student_Group.Add(stdgrp);
            db.SaveChanges();

            NotificationAdd(id);


            return(Json(new { success = true, msg = "Successfully sent" }, JsonRequestBehavior.AllowGet));
        }
        public IActionResult DelStudentGroup(DeleteStudentGroupRequest request)
        {
            // 参数校验
            if (!request.StudentGroupId.HasValue)
            {
                return(Ok("宿舍编号必填,不可为空"));
            }

            // 判断是否存在
            Student_Group studentGroup = _demoContext.DB.Queryable <Student_Group>().InSingle(request.StudentGroupId.Value);

            if (studentGroup == null)
            {
                return(Ok("该宿舍不存在"));
            }

            // 判断是否已删除
            if (studentGroup.IsDelete == 1)
            {
                return(Ok("该宿舍已删除"));
            }

            // 若宿舍中有人员则不可删除
            var number = _demoContext.DB.Queryable <Student_Group_Detail>().Where(it => it.StudentGroupId == request.StudentGroupId && it.IsDelete == 0).ToList();

            if (number.Count == 0)
            {
                // 0=未删除;1已删除
                studentGroup.IsDelete = 1;
                // 记录更新时间

                // 记录操作日志

                // 数据库影响行数
                int command = _demoContext.DB.Updateable <Student_Group>(studentGroup).ExecuteCommand();



                return(Ok(command > 0 ? "删除成功" : "删除失败"));
            }
            return(Ok("不可以删除"));
        }
        public IActionResult UpdateStuGroup(UpdateStudentGroupRequest request)
        {
            //宿舍id参数校验
            if (!request.StudentGroupId.HasValue)
            {
                //宿舍编号为空
                return(Failure(ResultCode.PARAM_IS_INVALLD));
            }
            //宿舍名参数校验
            if (request.StudentGroupName == "")
            {
                //宿舍名为空
                return(Failure(ResultCode.PARAM_NOT_COMPLETE));
            }
            Student_Group studentGroup = new Student_Group();

            studentGroup.StudentGroupId   = request.StudentGroupId;
            studentGroup.StudentGroupName = request.StudentGroupName;

            //查询宿舍名
            var studentgroupName = _demoContext.DB.Queryable <Student_Group>().InSingle(studentGroup.StudentGroupName);

            //判断是否可以查询到
            if (studentgroupName == null)
            {
                //修改宿舍
                int command = _demoContext.DB.Updateable(studentGroup).UpdateColumns(usg => new { usg.StudentGroupName }).ExecuteCommand();
                //判断更新语句是否执行完成
                if (command == 1)
                {
                    //修改成功
                    return(Success());
                }
                else
                {
                    //修改失败
                    return(Failure(ResultCode.SYSTEM_INNER_ERROR));
                }
            }
            //宿舍名重复
            return(Failure(ResultCode.PARAM_NAME_COMPLETE));
        }
Beispiel #5
0
        public List <Student_Group> Get_All_Student_Group()
        {
            Connect();
            List <Student_Group> GroupList = new List <Student_Group>();

            Log.For(this).Info("Showing roles");
            try
            {
                SqlCommand    command = new SqlCommand("SELECT * FROM Student_Group", Connection);
                SqlDataReader reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    Student_Group group = new Student_Group();
                    group.ID_Student_Group     = Convert.ToInt32(reader["ID_Student_Group"]);
                    group.Student_Group_Name   = Convert.ToString(reader["Student_Group_Name"]);
                    group.Student_Group_Number = Convert.ToInt32(reader["Student_Group_Number"]);
                    GroupList.Add(group);
                }
                reader.Close();
            }
            catch (Exception) { }
            finally { Disconnect(); }
            return(GroupList);
        }