Пример #1
0
        public OperationStatus Update(StudentDomain student)
        {
            Guard.WhenArgument(student, nameof(student)).IsNull().Throw();

            try
            {
                var studentEntity = _mappingService.Map <StudentEntity>(student);

                _entityFrameworkGenericRepository.Update(studentEntity);
                _unitOfWork.Commit();
            }
            catch (Exception ex)
            {
                if (ex.InnerException.InnerException.Message.Contains("Cannot insert duplicate key row in object"))
                {
                    return(new FailureStatus($"Ученик с номер { student.Number } вече съществува!"));
                }

                // TODO how to log classEntity?
                _loggingService.Error(ex);

                return(new FailureStatus("Възникна грешка при създаването на ученикът. Моля свържете се със ситемният администратор."));
            }

            return(new SuccessStatus());
        }
Пример #2
0
        private void UpdateAbsebces(List <StudentDomain> students, int selectedMonthId)
        {
            foreach (var student in students)
            {
                var studentAbsences = student.Absences.Where(x => x.MonthId < selectedMonthId).ToList();

                var totalExcusedAbsences    = studentAbsences.Sum(x => x.Excused);
                var totalNotExcusedAbsences = studentAbsences.Sum(x => x.NotExcused);

                var studentId      = _encryptingService.DecodeId(student.Id);
                var studentAbsence = student.Absences.LastOrDefault();

                if (studentAbsence != null)
                {
                    var absenseId = _encryptingService.DecodeId(studentAbsence.Id);

                    var absence = new AbsenceEntity()
                    {
                        Id         = absenseId,
                        Excused    = student.EnteredTotalExcusedAbsences - totalExcusedAbsences,
                        NotExcused = student.EnteredTotalNotExcusedAbsences - totalNotExcusedAbsences,
                        StudentId  = studentId,
                        MonthId    = selectedMonthId
                    };

                    _absenceRepository.Update(absence);
                }
                //if user do not fill row when update record
                else
                {
                    var absence = new AbsenceEntity()
                    {
                        Excused    = 0,
                        NotExcused = 0,
                        StudentId  = studentId,
                        MonthId    = selectedMonthId
                    };

                    _absenceRepository.Add(absence);
                }
            }
        }