Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6678787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:17:01+00:00 2026-05-26T04:17:01+00:00

I have written a method to generate commission slips for tutors in a system

  • 0

I have written a method to generate commission slips for tutors in a system for a college. Tutors have certain students enrolled with them at certain fees per month, and they earn a commission on these lessons they give. With this method, I am trying to calculate the total amount for ALL the enrollments belonging to the tutor (i.e. if they have 3 students and each student is enrolled for R460 a month, the total amount will be 1380 multiplied by their commission percentage.) Therefore, I want one commission slip generated (one database entry in the TutorCommission entity) for each tutor in the database with this total amount. Here is the code for this:

  public ActionResult CreateBulkCommissions()
        {
{
    var month = DateTime.Now.ToString("MMMM");

    var enrolments = db.Enrollments.ToList();
    var tutor = db.Tutors.ToList();

    IEnumerable<TutorCommission> tutorsCommissionsAlt = enrolments // Take the enrollments
        .GroupJoin( // This will group enrollments by the tutor
            tutor, // Join with the tutor's commission percentages.
            e => e.TutorNoID, // Use tutorNoID for left Key
            tcp => tcp.TutorNoID, // ... and right key
            (e, tcp) => new TutorCommission // Create entry which is the tutor and his total commission
            {
                TutorNoID = e.TutorNoID,
                CommissionAmount = (long)tcp.Sum(c => c.TutorCommissionPercentage * e.MonthlyFee),
                CommissionMonth = month,  // string constant 
                CommissionStatus = "Unpaid",
            });

    foreach (var com in tutorsCommissionsAlt)
    {
        db.TutorCommission.Add(com);
        db.SaveChanges();
    }

    return RedirectToAction("Index");
}
        }

At the moment, this code generates a new database entry for each enrollment (so if they have 20 enrollments, it will generate 20 database entries for the month). What changes can I make to this code that will put the total amount in one database entry for each tutor? Here are the relevant classes:

public class Enrollment
{
    [Key]
    [Display(Name = "Enrollment ID Number")]
    public long EnrollmentIDNumber { get; set; }
    [Display(Name = "Client ID Number")]
    public long ClientNumberID { get; set; }
    [Display(Name = "Tutor ID Number")]
    public long TutorNoID { get; set; }
    [Display(Name = "Course Name")]
    public string CourseName { get; set; }
    [Display(Name = "Lesson Time")]
    public string LessonTime { get; set; }
    [Display(Name = "Lesson Day")]
    public string LessonDay { get; set; }
    [Display(Name = "Lesson Location")]
    public string LessonLocation { get; set; }
    [Display(Name = "Lesson Type")]
    public string LessonType { get; set; }
    [Display(Name = "Lesson Level")]
    public string LessonLevel { get; set; }
    [Display(Name = "Monthly Fee")]
    public long MonthlyFee { get; set; }

    public virtual Client Client { get; set; }
    public virtual Tutor Tutor { get; set; }

}

public class TutorCommission
{
    [Key]
    [Display(Name = "Commission ID")]
    public long CommissionID { get; set; }
    [Display(Name = "Commission Month")]
    public string CommissionMonth {get; set;}
    [Display(Name = "Commission Amount")]
    public double CommissionAmount { get; set; }
    [Display(Name = "Commission Status")]
    public string CommissionStatus { get; set; }
    [Display(Name = "Tutor ID Number")]
    public long TutorNoID { get; set; }

    public virtual Tutor Tutor { get; set; }
    public virtual ICollection<CommissionPayments> CommissionPayments { get; set; }

}

public class Tutor
{
    [Key]
    [Display(Name = "Tutor ID Number")]
    public long TutorNoID { get; set; }
    [Required]
    [StringLength(50, ErrorMessage="First name must be less than 50 characters")]
    [Display(Name = "First Name")]
    public string TutorFirstName { get; set; }
    [StringLength(50, ErrorMessage = "Last name must be less than 50 characters")]
    [Display(Name = "Last Name")]
    public string TutorLastName { get; set; }
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
    [Display(Name = "Birth Date")]
    public DateTime? TutorBirthDate { get; set; }
    [Display(Name = "Cellphone Number")]
    public string TutorCellphoneNumber { get; set; }
    [Display(Name = "Home Number")]
    public string TutorHomeNumber { get; set; }
    [RegularExpression("^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$", ErrorMessage = "Not a valid email address")]
    [Display(Name = "Email Address")]
    public string TutorEmailAddress { get; set; }
    [Display(Name = "Street Address")]
    public string TutorStreetAddress { get; set; }
    [Display(Name = "Suburb")]
    public string TutorSuburb { get; set; }
    [Display(Name = "City")]
    public string TutorCity { get; set; }
    [Display(Name = "Postal Code")]
    public string TutorPostalCode { get; set; }
    [Display(Name="Full Name")]
    public string FullName
    {
        get
        {
            return TutorFirstName + " " + TutorLastName;
        }
    }
    [Display(Name="Commission Percentage")]
    [Required]
    public double TutorCommissionPercentage { get; set; }

    public virtual ICollection<Enrollment> Enrollments { get; set; }
    public virtual ICollection<TutorCommission> TutorCommissions { get; set; }

Thanks,
Amy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:17:02+00:00Added an answer on May 26, 2026 at 4:17 am

    It looks like you have your collections specified the wrong way around – shouldnt you be joining a list of enrolments to a single tutor?:

    IEnumerable<TutorCommission> tutorsCommissionsAlt = enrolments.GroupJoin(tutor ...
    

    Should be:

    IEnumerable<TutorCommission> tutorsCommissionsAlt = tutor.GroupJoin(enrolments...
    

    I’ve put this code together, and it seems to check out:

            var month = DateTime.Now.ToString("MMMM");
    
            var enrolments = new List<Enrollment>();
            enrolments.Add(new Enrollment { TutorNoID = 1, MonthlyFee = 1500 });
            enrolments.Add(new Enrollment { TutorNoID = 1, MonthlyFee = 4500 });
    
            var tutor = new List<Tutor>();
            tutor.Add(new Tutor { TutorNoID = 1, TutorCommissionPercentage = 0.5 });
    
    
            IEnumerable<TutorCommission> tutorsCommissionsAlt = tutor.GroupJoin(enrolments,
                    tut => tut.TutorNoID, 
                    enr => enr.TutorNoID,
                    (tut, enr) => new TutorCommission // Create entry which is the tutor and his total commission
                    {
                        TutorNoID = tut.TutorNoID,
                        CommissionAmount = (long)enr.Sum(c => c.MonthlyFee * tut.TutorCommissionPercentage),
                        CommissionMonth = month,  // string constant 
                        CommissionStatus = "Unpaid",
                    });
    
    
            foreach (var com in tutorsCommissionsAlt)
            {
                Console.WriteLine(com.CommissionAmount);
            }
    
    // Output: 3000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate a xml file. I have written a xml_generator method. When
I have written a method to calculate a given percentile for a set of
i have written a method in java like this public boolean ADD(String ID,String Name,String
I have written this clone method for when the parent of the Employee class
I have written an extension method for string manipulation. I'm confused what should I
I have a written a method to get all the records and return in
I have a method written in VB.NET. It looks like this: Shared Sub SomeMethod(ByVal
I have written a login form, in this I have used, form and method
I am writing some unit tests for an extension method I have written on
I have class1.m . I declared a method and written in it. Now i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.