示例#1
0
        [HttpPut("UpdateClassSectionUserMapping")] // for teacher
        public async Task <IActionResult> UpdateClassSectionUserMapping(ClassSectionUserDtoForUpdate classSectionUser)
        {
            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.UpdateClassSectionUserMapping(classSectionUser);

            return(Ok(_response));
        }
        public async Task UpdateClassSectionUserMapping_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var classesController = this.CreateClassesController();
            ClassSectionUserDtoForUpdate classSectionUser = null;

            // Act
            var result = await classesController.UpdateClassSectionUserMapping(
                classSectionUser);

            // Assert
            Assert.True(false);
            this.mockRepository.VerifyAll();
        }
示例#3
0
        public async Task <ServiceResponse <object> > UpdateClassSectionUserMapping(ClassSectionUserDtoForUpdate model)
        {
            try
            {
                var objToUpdate       = _context.ClassSectionUsers.FirstOrDefault(m => m.Id == model.Id);
                var oldUserId         = objToUpdate.UserId;
                var oldClassSectionId = objToUpdate.ClassSectionId;

                objToUpdate.ClassSectionId = model.ClassSectionId;
                objToUpdate.UserId         = model.UserId;
                objToUpdate.IsIncharge     = model.IsIncharge;
                _context.ClassSectionUsers.Update(objToUpdate);
                await _context.SaveChangesAsync();

                List <ClassSectionTransaction> ToAdd = new List <ClassSectionTransaction>();

                ToAdd.Add(new ClassSectionTransaction
                {
                    ClassSectionId     = oldClassSectionId,
                    UserId             = oldUserId,
                    MappedCreationDate = objToUpdate.CreatedDate,
                    UserTypeId         = _context.Users.FirstOrDefault(m => m.Id == objToUpdate.UserId && m.Active == true).UserTypeId,
                    DeletionDate       = DateTime.UtcNow,
                    DeletedById        = _LoggedIn_UserID
                });

                await _context.ClassSectionTransactions.AddRangeAsync(ToAdd);

                await _context.SaveChangesAsync();

                _serviceResponse.Success = true;
                _serviceResponse.Message = CustomMessage.Updated;
            }
            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);
        }