public ActionResult Create(int id, fee obj)
 {
     if (Session["id"] == null)
         return RedirectToAction("signin", "Home");
     try
     {
         // TODO: Add insert logic here
         schooldbEntities db = new schooldbEntities();
         string day = obj.Is_Paid ? DateTime.Today.Day.ToString() : "";
         List<student> stdList = (from tmp in db.students where tmp.familyId == id && tmp.StudentStatus == 1 select tmp).ToList();
         List<double?> sum = (from tmp in db.students where tmp.familyId == id && tmp.StudentStatus == 1 select tmp.StudentFee).ToList();
         double? discount = (from tmp in db.families where tmp.familyId == id select tmp.Discount).FirstOrDefault();
         long feeId = (from tmp in db.fees select tmp).LongCount();
         List<fee> feeList = (from tmp in db.fees
                               where tmp.Month == obj.Month && tmp.Year == obj.Year
                               select tmp).ToList();
         foreach (fee tmp in feeList)
         {
             foreach (student std in stdList)
             {
                 if (tmp.studentId == std.studentId) return View("AddError");
             }
         }
         double? netFee = sum.Sum() - (discount / 100 * sum.Sum());
         int i = 0;
         foreach (student tmp in stdList)
         {
             fee newObj = new fee { Id = (int)feeId + 1, Basic_Fee = (float)tmp.StudentFee, Concession = 0
             , Is_Paid = obj.Is_Paid, Month = obj.Month, Year = obj.Year,
             Net_Fee = i == 0 ? (float)(sum.Sum() - (discount / 100 * sum.Sum())) : 0, studentId = tmp.studentId
            , Day = obj.Is_Paid ? DateTime.Today.Day : 0
             };
             db.fees.AddObject(newObj);
             i++;
         }
         db.SaveChanges();
         return RedirectToAction("../Home/Family");
     }
     catch(Exception ex)
     {
         return View("AddError");
     }
 }
 /// <summary>
 /// Create a new fee object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="month">Initial value of the Month property.</param>
 /// <param name="year">Initial value of the Year property.</param>
 /// <param name="basic_Fee">Initial value of the Basic_Fee property.</param>
 /// <param name="net_Fee">Initial value of the Net_Fee property.</param>
 /// <param name="is_Paid">Initial value of the Is_Paid property.</param>
 /// <param name="studentId">Initial value of the studentId property.</param>
 /// <param name="day">Initial value of the Day property.</param>
 public static fee Createfee(global::System.Int32 id, global::System.String month, global::System.String year, global::System.Single basic_Fee, global::System.Single net_Fee, global::System.Boolean is_Paid, global::System.Int32 studentId, global::System.Int32 day)
 {
     fee fee = new fee();
     fee.Id = id;
     fee.Month = month;
     fee.Year = year;
     fee.Basic_Fee = basic_Fee;
     fee.Net_Fee = net_Fee;
     fee.Is_Paid = is_Paid;
     fee.studentId = studentId;
     fee.Day = day;
     return fee;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the fees EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTofees(fee fee)
 {
     base.AddObject("fees", fee);
 }
 public ActionResult Edit(int id, fee obj)
 {
     if (Session["id"] == null)
         return RedirectToAction("signin", "Home");
     try
     {
         // TODO: Add update logic here
         schooldbEntities db = new schooldbEntities();
         List<student> stdList = (from tmp in db.students where tmp.familyId == id && tmp.StudentStatus == 1
                                      select tmp).ToList();
         foreach (student std in stdList)
         {
             fee fee = (from tmp in db.fees where tmp.studentId == std.studentId && tmp.Month == obj.Month && tmp.Year == obj.Year select tmp).FirstOrDefault();
             fee.Is_Paid = obj.Is_Paid;
             if (obj.Is_Paid) fee.Day = DateTime.Today.Day;
         }
         db.SaveChanges();
         return RedirectToAction("../Home/Family");
     }
     catch
     {
         return View("Error");
     }
 }