Related Links

Bulk Database Entries - Commission

I am writing an MVC 3 project and I'm using entity framework. I've written a method that generates bulk database entries, and this is for Invoices. The system is for a college, so the invoices are generated from a class called Enrollments (the monthly fee
for a student is in Enrollments). This method works correctly, but now I am looking to generate commission slips for the tutors of the college. The amount of the tutors monthly commission would be the amount their specific students pay X the Commission percentage
they receive. I am unsure how to write the code for this. These are the relevant model classes:

So to generate the tutor commission database entries, students enrolled with the tutors along with their monthly fees need to be used from the Enrollment class, added together and multiplied by the commission percentage of the tutor. I would like this method
to generate the commission slips for each tutor in the database. The purpose of this is for a manager to click on a link in order to generate these entries for the current month.

Re: Bulk Database Entries - Commission

Thanks for your reply. Sorry for being difficult to follow! Yes, TutorCommission and TutorCommissionPercentage are linked through tutor. Each client is enrolled with a specific tutor at a specific time, day etc. So what the statement needs to do is find
out how many enrollments are linked to each tutor (through TutorNoID in the Enrollment class) and accumulate the monthly fees accordingly. And then multiply this total amount by the TutorCommissionPercentage. So, shouldn't the CommissionAmount = enrolment.MonthlyFee
have some sort of Sum() function to add all the amounts together? This is what I'm not sure how to do.

I've rewritten your statement below, with all the Invoice information changed to Commission:

that it cannot convert lambda expression to delegate type 'System.Func<DFPProductions_Default.Models.TutorCommission,int,bool>' because some of the return types in the block are not implicitly convertible to the delegate return type and that it cannot implicitly
convert type 'long' to 'bool'

Re: Bulk Database Entries - Commission

in this line i am grouping the comisions by the tutor object (I hope i am doing this free hand) then getting the sum of commissionamout for each tutor, times the times the tutors commissionpercentage. key repersents the tutor we grouped by. give it a go
and let me know how you went

Re: Bulk Database Entries - Commission

You were correct the first time in fact, I want it to be the total commission for all of the tutors enrollments, so it is more compex. I'm just not sure where to put your previous code? I have it like this:

And I have two errors. One here: { CommissionPercentage = enrolment.Tutor.TutorCommissionPercentage.CommissionPercentage } }, saying that 'System.Collections.Generic.ICollection' does not contain a definition for 'CommissionPercentage' and no extension method
'CommissionPercentage' accepting a first argument of type 'System.Collections.Generic.ICollection' could be found.

And g.Key.TutorCommissionPercentage.CommissionPercentage, that 'g' does not exist in the current context.

How would I change this line accordingly: Tutor = new Tutor { TutorNoID = enrolment.Tutor.TutorNoID, TutorCommissionPercentage = new TutorCommissionPercentage { CommissionPercentage = enrolment.Tutor.TutorCommissionPercentage } } now that I've made TutorCommissionPercentage
a property of Tutor?

And in this line: CommissionAmount = s.Sum(u => u.CommissionAmount) * s.Key.TutorCommissionPercentage, it says cannot implicitly convert type long to decimal. How would I explicitly convert it?

Re: Bulk Database Entries - Commission

Okay, I've change commission percentage to a double because I'm getting irritated with that error and I want to test if the method is working. Once I did that, the error went away, but now there is error here:

So I changed the last line to the above from Tutor = new Tutor { TutorNoID = enrolment.Tutor.TutorNoID, TutorCommissionPercentage = enrolment.Tutor.TutorCommissionPercentage } So there are no errors now and database entries are being added. The problem is, a database entry is added per enrollment and not per tutor (with a total amount) and the TutorCommissionPercentage is not having any effect as it is adding the full amount, and not the commission amount. Any thoughts?