public int CreateGroupJoiningRequest(GroupJoiningRequest groupJoiningRequest)
        {
            if (CheckStudentAlreadyHaveGroup(groupJoiningRequest.student_id))
            {
                throw new Exception("The student already belong to a group.");
            }
            if (CheckGroupJoiningRequestAlreadySentToGroup(groupJoiningRequest.student_id, groupJoiningRequest.group_id))
            {
                throw new Exception("Group Joining Request already sent to this group from this student.");
            }
            int numberOfRowsAffected;

            try
            {
                using (var connection = GetConnection())
                {
                    var p = new DynamicParameters();
                    p.Add("@" + GroupJoiningRequest.RequestDateDatabaseColumnName, value: groupJoiningRequest.request_date, dbType: DbType.DateTime);
                    p.Add("@" + GroupJoiningRequest.RequestAcceptanceDateDatabaseColumnName, value: groupJoiningRequest.request_acceptance_date, dbType: DbType.DateTime);
                    p.Add("@" + GroupJoiningRequest.StudentIdDatabaseColumnName, value: groupJoiningRequest.student_id, dbType: DbType.Int32);
                    p.Add("@" + GroupJoiningRequest.GroupIdDatabaseColumnName, value: groupJoiningRequest.group_id, dbType: DbType.Int32);
                    p.Add("@" + GroupJoiningRequest.NotifiedOfGroupJoiningRequestOutcome, value: null, dbType: DbType.Boolean);
                    numberOfRowsAffected = connection.Execute("createGroupJoiningRequestSP", p, commandType: CommandType.StoredProcedure);
                    return(numberOfRowsAffected);
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #2
0
        public ActionResult AcceptGroupJoiningRequest(int groupJoiningRequestId)
        {
            int numberOfRowsAffected = 0;
            GroupJoiningRequest groupJoiningRequest = groupJoiningRequestRepository.GetGroupJoiningRequestByGroupJoiningRequestId(groupJoiningRequestId);

            try
            {
                numberOfRowsAffected = groupJoiningRequestRepository.SetRequestAcceptanceDate(DateTime.Now, groupJoiningRequestId);
                groupJoiningRequestRepository.SetNotifiedOfGroupJoiningRequestOutcome(false, groupJoiningRequestId);
                groupRepository.AddGroupMember(groupJoiningRequest.student_id, groupJoiningRequest.group_id);
                groupJoiningRequestRepository.AutoRejectOtherGroupJoiningRequests(groupJoiningRequest.student_id);
                return(Json(new { rowsAffected = numberOfRowsAffected }));
            }
            catch (Exception e)
            {
                return(Json(new { rowsAffected = numberOfRowsAffected, error = e.Message }));
            }
        }