Example #1
0
 public ActionResult CreateDepartmentPost(DepartmentCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         var department = new DepartmentRecord {
             Name = model.Name
         };
         //create parent department.
         if (model.ParentDepartmentId.HasValue)
         {
             department.ParentDepartmentRecord = _departmentService.GetDepartment(model.ParentDepartmentId.Value);
         }
         //create postions.
         foreach (var item in model.AvailablePositions.Where(c => c.IsSelected).ToList())
         {
             department.PositionDepartmentRecords.Add(new PositionsDepartmentRecord {
                 DepartmentRecord = department, PositionRecord = new PositionRecord {
                     Id = item.Id
                 }
             });
         }
         _departmentService.CreateDepartment(department);
         _orchardServices.Notifier.Add(NotifyType.Information, T("The department information has been created."));
         return(RedirectToAction("EditDepartment", new { id = department.Id }));
     }
     model.UpdateViewModel(_departmentService.ListDepartments(), _departmentService.ListPositions());
     return(View(model));
 }
        public void Add(Student student, DepartmentRecord departmentRecord)
        {
            if (this.Validation(student))
            {
                return;
            }
            if (_departmentRecordService.Validation(departmentRecord))
            {
                return;
            }

            try
            {
                if (!_departmentRecordService.IsStudentRegistered(student.Tc))
                {
                    _studentDal.Add(student);
                }
                _departmentRecordService.Add(departmentRecord);
                Message.Info("Kayıt Başarılı!");
            }
            catch (Exception exp)
            {
                Message.Error("Hata oluştu\n" + exp.Message);
            }
        }
Example #3
0
        public bool Validation(DepartmentRecord entity)
        {
            if (string.IsNullOrEmpty(entity.StudentNo))
            {
                Message.Error("Öğrenci Numarası Boş olamaz!");
                return(true);
            }
            if (entity.StudentNo.Length != 9)
            {
                Message.Error("Öğrenci Numarası 9 karakterden oluşabilir!");
                return(true);
            }

            if (!Regex.IsMatch(entity.StudentNo, "^[0-9]*$"))
            {
                Message.Error("Öğrenci Numarası sadece Rakamlardan oluşabilir.");
                return(true);
            }
            var str = entity.DepartmentCode.Substring(1, entity.DepartmentCode.Length - 1);

            if (!entity.StudentNo.StartsWith(str))
            {
                Message.Error("Öğrenci numarası bölüm kodu ile başlamalıdır.");
                return(true);
            }

            if (_departmentRecord.Get(p => p.StudentNo.Equals(entity.StudentTc)) != null)
            {
                Message.Error("Öğrenci Numarası Mevcut!");
                return(true);
            }

            if (_departmentRecord.Get(p => p.StudentTc.Equals(entity.StudentTc) && p.Major.Equals(Major.CiftAnaDal)) != null)
            {
                Message.Error("Öğrenci Her iki bölümede kayıtlı!");
                return(true);
            }

            if (IsStudentRegistered(entity.StudentTc))
            {
                if (_departmentRecord.Get(p => p.StudentTc.Equals(entity.StudentTc) && p.DepartmentCode.Equals(entity.DepartmentCode)) != null)
                {
                    Message.Error($"Zaten öğrenci {entity.DepartmentCode} bölümüne kayıtlı!");
                    return(true);
                }

                entity.Major = Major.CiftAnaDal;
            }


            return(false);
        }
Example #4
0
        public static DepartmentEditViewModel CreateEditModel(this DepartmentRecord model, IList <DepartmentRecord> departments, IList <PositionRecord> positions)
        {
            var editModel = new DepartmentEditViewModel();

            editModel.InjectFrom(model, new object[] { "Id", "Name" });
            if (model.ParentDepartmentRecord != null)
            {
                editModel.ParentDepartmentId = model.ParentDepartmentRecord.Id;
            }
            var availablePositions = positions.Select(c => c.CreateAvailablePosition()).ToList();

            if (model.PositionDepartmentRecords.Any())
            {
                foreach (var item in availablePositions)
                {
                    item.IsSelected = model.PositionDepartmentRecords.Any(c => c.PositionRecord.Id == item.Id);
                }
            }
            editModel.AvailableDepartments = departments;
            editModel.AvailablePositions   = availablePositions;
            return(editModel);
        }
Example #5
0
 public void Update(DepartmentRecord entity)
 {
     _departmentRecord.Update(entity);
 }
Example #6
0
 public void Delete(DepartmentRecord entity)
 {
     _departmentRecord.Delete(entity);
 }
Example #7
0
 public void Add(DepartmentRecord entity)
 {
     _departmentRecord.Add(entity);
 }
Example #8
0
 public void UpdateDepartment(DepartmentRecord record)
 {
     _departmentRepository.Value.Update(record);
 }