Exemplo n.º 1
0
        public async Task <IActionResult> UpdateClassSectionMapping(ClassSectionDtoForUpdate classSection)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //if (await _repo.ClassSectionExists(classSection.ClassId, classSection.SectionId))
            //    return BadRequest(new { message = "Class Section Already Exist" });

            _response = await _repo.UpdateClassSectionMapping(classSection);

            return(Ok(_response));
        }
Exemplo n.º 2
0
        public async Task UpdateClassSectionMapping_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var classesController = this.CreateClassesController();
            ClassSectionDtoForUpdate classSection = null;

            // Act
            var result = await classesController.UpdateClassSectionMapping(
                classSection);

            // Assert
            Assert.True(false);
            this.mockRepository.VerifyAll();
        }
Exemplo n.º 3
0
        public async Task <ServiceResponse <object> > UpdateClassSectionMapping(ClassSectionDtoForUpdate model)
        {
            try
            {
                var objToUpdate = _context.ClassSections.Where(m => m.Id == model.Id && m.Active == true).FirstOrDefault();
                if (objToUpdate != null)
                {
                    if (model.NumberOfStudents < objToUpdate.NumberOfStudents)
                    {
                        _serviceResponse.Success = false;
                        _serviceResponse.Message = CustomMessage.NoOfStudentLimitIsLowerNow;
                        return(_serviceResponse);
                    }
                    objToUpdate.ClassId    = model.ClassId > 0 ? model.ClassId : null;
                    objToUpdate.SemesterId = model.SemesterId > 0 ? model.SemesterId : null;
                    objToUpdate.SectionId  = model.SectionId;
                    objToUpdate.Active     = model.Active;
                    //objToUpdate.SchoolBranchId = _LoggedIn_BranchID;
                    objToUpdate.NumberOfStudents = model.NumberOfStudents;

                    await _context.SaveChangesAsync();

                    _serviceResponse.Success = true;
                    _serviceResponse.Message = CustomMessage.Updated;
                }
                else
                {
                    _serviceResponse.Success = false;
                    _serviceResponse.Message = CustomMessage.RecordNotFound;
                }
            }
            catch (DbUpdateException ex)
            {
                if (ex.InnerException.Message.Contains("Cannot insert duplicate key row"))
                {
                    _serviceResponse.Success = false;
                    _serviceResponse.Message = CustomMessage.SqlDuplicateRecord;
                }
                else
                {
                    throw ex;
                }
            }
            return(_serviceResponse);
        }