/// <summary>
        /// Method for updating an existing fee component - RS
        /// </summary>
        /// <param name="currentUserInstituteId"></param>
        /// <param name="updatedFeeComponent"></param>
        /// <returns></returns>
        public async Task <dynamic> UpdateFeeComponentAsync(int currentUserInstituteId, FeeComponent updatedFeeComponent)
        {
            FeeComponent existingFeeComponent = await _imsDbContext.FeeComponents.FirstOrDefaultAsync(x => x.Id == updatedFeeComponent.Id && x.InstituteId == currentUserInstituteId);

            if (existingFeeComponent == null)
            {
                return(new { Message = "No fee component found with this id", HasError = true });
            }
            else if (await _imsDbContext.FeeComponents.AnyAsync(x => x.Id != updatedFeeComponent.Id && x.Name.ToLowerInvariant().Equals(updatedFeeComponent.Name.ToLower())))
            {
                return(new { Message = "Fee Component already exist with this name", HasError = true });
            }
            else if (await _imsDbContext.FeeComponents.AnyAsync(x => x.Id != updatedFeeComponent.Id && x.InstituteId == currentUserInstituteId &&
                                                                x.Priority == updatedFeeComponent.Priority && updatedFeeComponent.Priority != 0))
            {
                return(new { DuplicatePriorityMessage = "Fee Component already exist with this priority", HasError = true });
            }

            existingFeeComponent.Name             = updatedFeeComponent.Name;
            existingFeeComponent.FeeComponentType = updatedFeeComponent.FeeComponentType;
            existingFeeComponent.Priority         = updatedFeeComponent.Priority;
            _imsDbContext.FeeComponents.Update(existingFeeComponent);
            await _imsDbContext.SaveChangesAsync();

            return(new { Message = "Fee Component updated successfully", HasError = false });
        }
        public async Task <IActionResult> AddNewFeeComponentAsync([FromBody] FeeComponent addedFeeComponent)
        {
            int currentUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

            ApplicationUser currentUser = await _userManager.FindByEmailAsync(User.Identity.Name);

            return(Ok(await _feeManagementRepository.AddNewFeeComponentAsync(addedFeeComponent, currentUser, currentUserInstituteId)));
        }
        /// <summary>
        /// Method for adding new fee component - RS
        /// </summary>
        /// <param name="addedFeeComponent"></param>
        /// <param name="currentUser"></param>
        /// <param name="currentUserInstituteId"></param>
        /// <returns></returns>
        public async Task <dynamic> AddNewFeeComponentAsync(FeeComponent addedFeeComponent, ApplicationUser currentUser, int currentUserInstituteId)
        {
            if (await _imsDbContext.FeeComponents.AnyAsync(x => x.InstituteId == currentUserInstituteId && x.Name.ToLowerInvariant().Equals(addedFeeComponent.Name.ToLowerInvariant())))
            {
                return(new { Message = "Fee Component already exist with this name", HasError = true });
            }
            else if (await _imsDbContext.FeeComponents.AnyAsync(x => x.InstituteId == currentUserInstituteId && x.Priority == addedFeeComponent.Priority && addedFeeComponent.Priority != 0))
            {
                return(new { DuplicatePriorityMessage = "Fee Component already exist with this priority", HasError = true });
            }

            addedFeeComponent.InstituteId = currentUserInstituteId;
            addedFeeComponent.CreatedBy   = currentUser.Id;
            addedFeeComponent.CreatedOn   = DateTime.UtcNow;
            _imsDbContext.FeeComponents.Add(addedFeeComponent);
            await _imsDbContext.SaveChangesAsync();

            return(new { Message = "Fee Component added successfully", HasError = false });
        }
        public async Task <IActionResult> UpdateFeeComponentAsync([FromBody] FeeComponent updatedFeeComponent)
        {
            int currentUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

            return(Ok(await _feeManagementRepository.UpdateFeeComponentAsync(currentUserInstituteId, updatedFeeComponent)));
        }