public async Task <IActionResult> AddSemesterFeeMapping(SemesterFeeMappingDtoForAdd model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _response = await _repo.AddSemesterFeeMapping(model); return(Ok(_response)); }
public async Task <ServiceResponse <object> > AddSemesterFeeMapping(SemesterFeeMappingDtoForAdd model) { var ToAdd = new SemesterFeeMapping { SemesterId = Convert.ToInt32(model.SemesterId), ClassId = Convert.ToInt32(model.ClassId), StudentId = Convert.ToInt32(model.StudentId), DiscountInPercentage = Convert.ToInt32(model.DiscountInPercentage), Remarks = model.Remarks, FeeAfterDiscount = Convert.ToDouble(model.FeeAfterDiscount), Installments = Convert.ToInt32(model.Installments), Posted = false, CreatedDateTime = DateTime.UtcNow, CreatedById = _LoggedIn_UserID, SchoolBranchId = _LoggedIn_BranchID, }; await _context.SemesterFeeMappings.AddAsync(ToAdd); await _context.SaveChangesAsync(); if (ToAdd.Installments > 1) { var installmentAmount = ToAdd.FeeAfterDiscount / ToAdd.Installments; List <FeeInstallment> ListToAdd = new List <FeeInstallment>(); for (int i = 0; i < ToAdd.Installments; i++) { var ToAdd2 = new FeeInstallment { SemesterFeeMappingId = ToAdd.Id, PaidMonth = null, Amount = installmentAmount, Paid = false, Active = true, CreatedDateTime = DateTime.UtcNow, CreatedById = _LoggedIn_UserID, SchoolBranchId = _LoggedIn_BranchID, }; ListToAdd.Add(ToAdd2); } await _context.FeeInstallments.AddRangeAsync(ListToAdd); await _context.SaveChangesAsync(); } _serviceResponse.Success = true; _serviceResponse.Message = CustomMessage.Added; return(_serviceResponse); }