Beispiel #1
0
        //  [Authorize(Roles = "AddGroup")]
        public IActionResult Create([FromBody] AddGroupDTO addGroupDto)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(addGroupDto.Name))
                {
                    var message = Messages.EmptyName;
                    message.ActionName     = "Add Group";
                    message.ControllerName = "Group";
                    return(BadRequest(message));
                }
                // test if there is another group with the same name
                Group group = _groupRepositroy.Get(c => c.Name == addGroupDto.Name).FirstOrDefault();
                if (group != null)
                {
                    var message = Messages.Exist;
                    message.ActionName     = "Add Group";
                    message.ControllerName = "Group";
                    return(Conflict(message));
                }
                var        priveleges  = _privilageRepositroy.Get().Select(c => c.Id);
                List <int> privelgesId = addGroupDto.Priveleges;

                if (privelgesId != null)
                {
                    // test if theres an priveleg Id not in database
                    if (privelgesId.Except(priveleges).Any())
                    {
                        var message = Messages.NotFound;
                        message.ActionName     = "Add Group";
                        message.ControllerName = "Group";
                        message.Message        = "الصلاحية غير موجودة";
                        return(NotFound(message));
                    }
                }

                group = new Group()
                {
                    Name = addGroupDto.Name
                };
                _abstractUnitOfWork.Add(group, UserName());
                // for add group without priveleges
                if (privelgesId != null)
                {
                    foreach (var item in addGroupDto.Priveleges)
                    {
                        _abstractUnitOfWork.Add(new GroupPrivilage()
                        {
                            GroupId = group.Id, PrivilageId = item
                        }, UserName());
                    }
                }
                _abstractUnitOfWork.Commit();
                return(Ok(_mapper.Map <GroupResopnseDTO>(group)));
            }
            catch (Exception)
            {
                return(BadRequestAnonymousError());
            }
        }
Beispiel #2
0
        //[Authorize(Roles = "AddUser")]
        public IActionResult AddUser([FromBody] AddUserDTO addUserDTO)
        {
            try
            {
                addUserDTO.Name = addUserDTO.Name.Trim();
                User simelarUserName = _userRepositroy.Get(c => c.Username == addUserDTO.Username).FirstOrDefault();
                if (simelarUserName != null)
                {
                    var message = Messages.Exist;
                    message.ActionName     = "Add User";
                    message.ControllerName = "User";
                    return(Conflict(message));
                }

                User user = _mapper.Map <User>(addUserDTO);
                user.Password = MD5Hash.GetMd5Hash(user.Password);

                //check  for groups Id
                var groupsId = _groupRepository.Get().Select(c => c.Id);
                if (addUserDTO.GroupIds != null && addUserDTO.GroupIds.Count > 0)
                {
                    if (addUserDTO.GroupIds.Except(groupsId).Any())
                    {
                        var message = Messages.NotFound;
                        message.ActionName     = "Add User";
                        message.ControllerName = "User";
                        message.Message        = "يوجد مجموعة على الاقل غير موجودة";
                        return(NotFound(message));
                    }
                }
                //end checking
                _abstractUnitOfWork.Add(user, UserName());
                if (addUserDTO.GroupIds != null && addUserDTO.GroupIds.Count > 0)
                {
                    foreach (var item in addUserDTO.GroupIds)
                    {
                        UserGroup userGroup = new UserGroup()
                        {
                            UserId  = user.Id,
                            GroupId = item,
                        };
                        _abstractUnitOfWork.Add(userGroup, UserName());
                    }
                }
                _abstractUnitOfWork.Commit();
                return(Ok(_mapper.Map <UserResponDTO>(user)));
            }
            catch (Exception ex)
            {
                return(BadRequest(Messages.AnonymousError));
            }
        }
Beispiel #3
0
        //[Authorize(Roles = "AddSubject")]
        public IActionResult Add([FromBody] AddSubjectDTO addSubjectDTO)
        {
            try
            {
                addSubjectDTO.Name = addSubjectDTO.Name.Trim();
                var simelarCode = _subjectRepositroy.Get(c => c.SubjectCode == addSubjectDTO.SubjectCode).FirstOrDefault();
                if (simelarCode != null)
                {
                    var message = Messages.Exist;
                    message.ActionName     = "Add";
                    message.ControllerName = "Subject";
                    return(Conflict(message));
                }

                var subjectType = _subjectTypeRepositroy.Find(addSubjectDTO.SubjectTypeId);
                if (subjectType == null)
                {
                    var message = Messages.NotFound;
                    message.ActionName     = "Add";
                    message.ControllerName = "Subject";
                    message.Message        = "نوع المادة غير موجود";
                    return(Conflict(message));
                }
                var semester = _studySemesterRepositroy.GetIQueryable(c => c.Id == addSubjectDTO.StudySemesterId)
                               .Include(c => c.Studyplan)
                               .ThenInclude(c => c.Year)
                               .FirstOrDefault();
                if (semester == null)
                {
                    var message = Messages.NotFound;
                    message.ActionName     = "Add";
                    message.ControllerName = "Subject";
                    message.Message        = "الفصل التدريسي غير موجود";
                    return(NotFound(message));
                }
                if (semester.Studyplan.Year.Blocked)
                {
                    var message = Messages.NotFound;
                    message.ActionName     = "Add";
                    message.ControllerName = "Subject";
                    message.Message        = "لا يمكن تعديل الخطة ";
                    return(Conflict(message));
                }
                var subject = _mapper.Map <Subjects>(addSubjectDTO);
                _abstractUnitOfWork.Add(subject, UserName());
                subject.StudySemester = semester;
                foreach (var item in addSubjectDTO.DependencySubjectsId)
                {
                    var depencaySubject = _subjectRepositroy.GetIQueryable(c => c.Id == item)
                                          .Include(c => c.StudySemester).FirstOrDefault();
                    var checking = _subjectServices.CheckSubjectAndDepandcySubject(subject, depencaySubject);
                    if (!checking)
                    {
                        return(Conflict());//؟؟؟؟
                    }
                    DependenceSubject dependenceSubject = new DependenceSubject
                    {
                        SubjectId          = subject.Id,
                        DependsOnSubjectId = item
                    };
                    _abstractUnitOfWork.Add(dependenceSubject, UserName());
                }
                foreach (var item in addSubjectDTO.EquivalentSubjectsId)
                {
                    var equivalentSubject = _subjectRepositroy.Find(item);
                    if (equivalentSubject == null)
                    {
                        var message = Messages.NotFound;
                        message.ActionName     = "Add";
                        message.ControllerName = "Subject";
                        message.Message        = "المادةالمكافئة غير موجودة";
                        return(NotFound(message));
                    }
                    EquivalentSubject eq = new EquivalentSubject()
                    {
                        FirstSubject   = subject.Id,
                        SecoundSubject = item
                    };
                    _abstractUnitOfWork.Add(eq, UserName());
                }
                _abstractUnitOfWork.Commit();
                return(Ok(subject));
            }
            catch
            {
                return(BadRequestAnonymousError());
            }
        }
Beispiel #4
0
 public IActionResult Add(AddYearSystemDTO addYearSystemDTO)
 {
     try
     {
         addYearSystemDTO.Name = addYearSystemDTO.Name.Trim();
         if (string.IsNullOrWhiteSpace(addYearSystemDTO.Name))
         {
             var message = Messages.EmptyName;
             message.ActionName     = "Add";
             message.ControllerName = "Year System";
             return(BadRequest(message));
         }
         var settingId    = addYearSystemDTO.Settings.Select(c => c.Id).ToList();
         var mainSettinId = this._settingsRepositroy.Get().Select(c => c.Id).ToList();
         // this number of role shoud replace in correct way
         if (settingId.Count < mainSettinId.Count())
         {
             var message = new BadRequestErrors();
             message.ActionName     = "Add";
             message.ControllerName = "Year System";
             message.Message        = "لم يتم إرسال كامل الإعدادات";
             return(Conflict(message));
         }
         settingId.Sort();
         if (settingId.Except(mainSettinId).Any() || mainSettinId.Except(settingId).Any())
         {
             var message = new BadRequestErrors()
             {
                 ActionName     = "Add",
                 ControllerName = "Year System",
                 Message        = "لام يتم إرسال جميع الإعدادات او تم إرسال قيمة خاطئة"
             };
             return(Conflict(message));
         }
         if (addYearSystemDTO.IsMain)
         {
             var oldMain = _abstractUnitOfWork.Repository <YearSystem>().Get(c => c.IsMain).FirstOrDefault();
             if (oldMain != null)
             {
                 oldMain.IsMain = false;
                 _abstractUnitOfWork.Repository <YearSystem>().Update(oldMain, UserName());
             }
         }
         YearSystem yearSystem = _mapper.Map <YearSystem>(addYearSystemDTO);
         _abstractUnitOfWork.Add(yearSystem, UserName());
         foreach (var item in addYearSystemDTO.Settings)
         {
             var setting           = _settingsRepositroy.Find(item.Id);
             var settingYearSystem = new SettingYearSystem
             {
                 YearSystem = yearSystem.Id,
                 Setting    = setting,
                 Count      = item.Count,
                 Note       = item.Note
             };
             _abstractUnitOfWork.Add(settingYearSystem, UserName());
         }
         _abstractUnitOfWork.Commit();
         return(Ok(_mapper.Map <ResponseYearSystem>(yearSystem)));
     }
     catch (Exception ex)
     {
         return(BadRequestAnonymousError());
     }
 }
Beispiel #5
0
        //[Authorize(Roles = "AddStudyPlan")]
        public IActionResult Add([FromBody] AddStudyPalnDTO addStudyPalnDTO)
        {
            try
            {
                var year = _yearRepositroy.Find(addStudyPalnDTO.YearId);
                if (year == null)
                {
                    var message = Messages.NotFound;
                    message.ActionName     = "Add Study Plan";
                    message.ControllerName = "Study Plan";
                    message.Message        = "السنة غير موجودة";
                    return(NotFound(message));
                }
                var specialization = _specializationsRepositroy.Find(addStudyPalnDTO.SpecializationId);
                if (specialization == null)
                {
                    var message = Messages.NotFound;
                    message.ActionName     = "Add Study Plan";
                    message.ControllerName = "Study Plan";
                    message.Message        = "الاختصاص غير موجود";
                    return(NotFound(message));
                }

                #region check temporary Id
                var tempId = addStudyPalnDTO.Subjects.Select(c => c.AddSubjectDTO.TempId).ToArray();
                if (tempId.Contains(0))
                {
                    var message = new BadRequestErrors();
                    message.ActionName     = "Update";
                    message.ControllerName = "YearSystem";
                    message.Message        = "الرجاء إعادة تحميل الصفحة";
                    return(Conflict(message));
                }
                if (tempId.Count() != tempId.Distinct().Count())
                {
                    var message = new BadRequestErrors();
                    message.ActionName     = "Update";
                    message.ControllerName = "YearSystem";
                    message.Message        = "الرجاء إعادة تحميل الصفحة";
                    return(Conflict(message));
                }
                #endregion


                #region check subject
                //but it should replace after asking the Eng
                //check subject
                var studyYear       = _studyYearRepositroy.Get().ToList();
                var subjectsTypesId = _subjectTypeRepositroy.Get().Select(c => c.Id);
                var subjectsId      = _subjectRepositroy.Get().Select(c => c.Id);
                foreach (var item in addStudyPalnDTO.Subjects)
                {
                    //there's not thered study semester
                    if (item.StudySemesterNumber > 2)
                    {
                        var message = Messages.NotFound;
                        message.ActionName     = "Add Study Plan";
                        message.ControllerName = "Study Plan";
                        message.Message        = "ليست 3 فصول تدريسية";
                        return(Conflict(message));
                    }
                    //chekc if all the year is correct
                    //example
                    //this subject is for thered year and in our collage don't have any thered year yet
                    //so it return an confliect
                    if (studyYear.Select(c => c.Id).ToList().IndexOf(item.StudyYearId) < 0)
                    {
                        var message = new BadRequestErrors();
                        message.ActionName     = "Add Study Plan";
                        message.ControllerName = "Study Plan";
                        message.Message        = "السنة الدراسية غير موجودة";
                        return(Conflict(message));
                    }

                    //check Type if exist
                    if (!subjectsTypesId.Contains(item.AddSubjectDTO.SubjectTypeId))
                    {
                        var message = Messages.NotFound;
                        message.ActionName     = "Add Study Plan";
                        message.ControllerName = "Study Plan";
                        message.Message        = "نوع المادة غير موجود";

                        return(NotFound(message));
                    }
                    var subject = item.AddSubjectDTO;
                    //befor tempId
                    //if (subject.DependencySubjectsId.Except(subjectsId).Any())
                    //{
                    //    return Conflict();
                    //}
                    subject.Name = subject.Name.Trim();
                    if (string.IsNullOrWhiteSpace(subject.Name))
                    {
                        var message = Messages.EmptyName;
                        message.ActionName     = "Add Study Plan";
                        message.ControllerName = "Study Plan";
                        return(Conflict(message));
                    }
                    if (subject.DependencySubjectsId.Except(tempId).Any())
                    {
                        var message = Messages.ReLoadPage;
                        message.ActionName     = "Add Study Plan";
                        message.ControllerName = "Study Plan";
                        return(Conflict(message));
                    }
                    if (subject.EquivalentSubjectsId.Except(subjectsId).Any())
                    {
                        var message = Messages.ReLoadPage;
                        message.ActionName     = "Add Study Plan";
                        message.ControllerName = "Study Plan";
                        return(Conflict(message));
                    }
                    subject.DependencySubjectsId = subject.DependencySubjectsId.Distinct().ToList();
                    subject.EquivalentSubjectsId = subject.EquivalentSubjectsId.Distinct().ToList();
                }
                #endregion

                var studyPaln = _mapper.Map <StudyPlan>(addStudyPalnDTO);
                _abstractUnitOfWork.Add(studyPaln, UserName());
                Dictionary <int, Subjects> tempIdAndSubject = new Dictionary <int, Subjects>();
                for (int i = 1; i <= studyYear.Count(); i++)
                {
                    //get the subject for this year mean first year and secound year ..etc
                    var subjectsForYear = addStudyPalnDTO.Subjects.Where(c => c.StudyYearId == studyYear[i - 1].Id);
                    //for adding in semester
                    //semester number because we have 2 semester in the year
                    for (int semesterNumber = 1; semesterNumber <= 2; semesterNumber++)
                    {
                        var semester = new StudySemester()
                        {
                            Number      = (short)semesterNumber,
                            StudyYearId = studyYear[i - 1].Id,
                            StudyplanId = studyPaln.Id,
                        };
                        _abstractUnitOfWork.Add(semester, UserName());
                        //get subject for the semester
                        var subjectsForSemester = subjectsForYear.Where(c => c.StudySemesterNumber == semesterNumber);
                        #region explain
                        //the output is like subject for first yaer and semester 1 in the first looping .
                        //exmple of output for Specialization Softwere engineering.
                        // programing 1 , electorinec , math1 , operaing system 1
                        //in the secound loop for the inner loop
                        //out put example
                        //programing 2 , math2 ,e2 ,
                        //in the seocund loop for the outer loop and first loop for inner loop
                        // advance programing 1 , oracle 1 ,operaing system 2
                        // this example depend on input


                        //for git subject without any extande proraty
                        #endregion
                        var finalSubjectAfterFilering = subjectsForSemester.Select(c => c.AddSubjectDTO).ToList();
                        finalSubjectAfterFilering.ForEach(c => c.StudySemesterId = semester.Id);
                        foreach (var subjectDTO in finalSubjectAfterFilering)
                        {
                            var subject = _mapper.Map <Subjects>(subjectDTO);
                            subject.StudySemester = semester;
                            _abstractUnitOfWork.Add(subject, UserName());
                            //foreach (var DependencySubjectId in subjectDTO.DependencySubjectsId)
                            //{
                            //    _abstractUnitOfWork.Repository<DependenceSubject>()
                            //        .Add(new DependenceSubject()
                            //        {
                            //            SubjectId = subject.Id,
                            //            DependsOnSubjectId = DependencySubjectId
                            //        }, UserName());
                            //}
                            tempIdAndSubject[subjectDTO.TempId] = subject;
                            foreach (var EquivalentSubjectId in subjectDTO.EquivalentSubjectsId)
                            {
                                _abstractUnitOfWork.Add(new EquivalentSubject()
                                {
                                    FirstSubject   = subject.Id,
                                    SecoundSubject = EquivalentSubjectId
                                }, UserName());
                            }
                        }
                    }
                }

                foreach (var subjectDTO in addStudyPalnDTO.Subjects.Select(c => c.AddSubjectDTO))
                {
                    var subject = tempIdAndSubject[subjectDTO.TempId];
                    foreach (var DependancySubjectId in subjectDTO.DependencySubjectsId)
                    {
                        var depenacySubjct = tempIdAndSubject[DependancySubjectId];

                        // if this subject can't depand on another subject
                        if (!_subjectServices.CheckCanBeDepandacy(subject, depenacySubjct))
                        {
                            var message = new BadRequestErrors();
                            message.ActionName     = "Add Study Plan";
                            message.ControllerName = "Study Plan";
                            message.Message        = "خطأ في تحديد اعتمادية المواد";
                            return(Conflict());
                        }
                        _abstractUnitOfWork.Add(
                            new DependenceSubject()
                        {
                            SubjectId          = subject.Id,
                            DependsOnSubjectId = depenacySubjct.Id
                        }, UserName());
                    }
                }
                _abstractUnitOfWork.Commit();
                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequestAnonymousError());
            }
        }