public async Task <IActionResult> UpdateStudentPromotionAsync([FromBody] UpdateStudentPromotionManagementAc updateStudentPromotion)
        {
            var loggedInUser = await _userManager.FindByNameAsync(User.Identity.Name);

            var classIds = new List <int>()
            {
                updateStudentPromotion.CurrentClassId, updateStudentPromotion.PromotedToClassId
            };

            classIds = classIds.Distinct().ToList();
            var classCount = await _iMSDbContext.InstituteClasses.CountAsync(x => classIds.Contains(x.Id));

            var sectionIds = new List <int>()
            {
                updateStudentPromotion.CurrentSectionId, updateStudentPromotion.PromotedToSectionId
            };
            var sectionCount = await _iMSDbContext.Sections.CountAsync(x => sectionIds.Contains(x.Id));

            sectionIds = sectionIds.Distinct().ToList();
            if (classCount != classIds.Count)
            {
                return(Ok(new StudentPromotionManagementResponse()
                {
                    HasError = true, Message = "Class not found", ErrorType = StudentPromotionManagementResponseType.ClassId
                }));
            }
            else if (sectionIds.Count != sectionCount)
            {
                return(Ok(new StudentPromotionManagementResponse()
                {
                    HasError = true, Message = "Section not found", ErrorType = StudentPromotionManagementResponseType.SectionId
                }));
            }
            else
            {
                return(Ok(await _studentPromotionManagementRepository.UpdateStudentPromotionAsync(updateStudentPromotion, loggedInUser)));
            }
        }
Example #2
0
        /// <summary>
        /// Method to update student promotion - SS
        /// </summary>
        /// <param name="updateStudentPromotion">student detail</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>respose</returns>
        public async Task <StudentPromotionManagementResponse> UpdateStudentPromotionAsync(UpdateStudentPromotionManagementAc
                                                                                           updateStudentPromotion, ApplicationUser loggedInUser)
        {
            var student = await _iMSDbContext.StudentBasicInformation.FirstOrDefaultAsync(x => x.Id == updateStudentPromotion.StudentId);

            if (student != null)
            {
                var promotion = await _iMSDbContext.StudentPromotionMappings.FirstOrDefaultAsync(x => x.Id == updateStudentPromotion.Id);

                if (promotion == null)
                {
                    return new StudentPromotionManagementResponse()
                           {
                               HasError = true, Message = "Student not found", ErrorType = StudentPromotionManagementResponseType.StudentId
                           }
                }
                ;
                else
                {
                    student.CurrentClassId = updateStudentPromotion.PromotedToClassId;

                    student.SectionId             = updateStudentPromotion.PromotedToSectionId;
                    promotion.PromotedToClassId   = updateStudentPromotion.PromotedToClassId;
                    promotion.PromotedToSectionId = updateStudentPromotion.PromotedToSectionId;
                    promotion.UpdatedById         = loggedInUser.Id;
                    promotion.UpdatedOn           = DateTime.UtcNow;
                    promotion.Remark = updateStudentPromotion.Remark;
                    _iMSDbContext.StudentBasicInformation.Update(student);
                    _iMSDbContext.StudentPromotionMappings.Update(promotion);
                    await _iMSDbContext.SaveChangesAsync();

                    return(new StudentPromotionManagementResponse()
                    {
                        HasError = false, Message = "Student detail updated successfully"
                    });
                }
            }
            else
            {
                return new StudentPromotionManagementResponse()
                       {
                           HasError = true, Message = "Student not found", ErrorType = StudentPromotionManagementResponseType.StudentId
                       }
            };
        }

        #endregion
    }