private decimal GetInducteeFeedbackAverage(List <DateTime> batchDateList, InducteeModel selectedInductee, ReportModel reportModel, InducteeModel inductee) { var feedBacks = db.Feedback.Where(m => m.InducteeID == inductee.Id).ToList(); decimal inudcteeSum = 0.0M; foreach (DateTime date in batchDateList) { decimal sum = GetFeedbackAverageByDate(feedBacks, date); inudcteeSum += sum; if (selectedInductee != null && inductee.Id == selectedInductee.Id) { reportModel.FeedBacks.Add(new ReportFeedbackModel() { Date = date, Score = sum }); } } decimal inudcteeAvg = Math.Round(inudcteeSum / batchDateList.Count, 2); if (selectedInductee != null && inductee.Id == selectedInductee.Id) { reportModel.InducteeAverage = inudcteeAvg; } return(inudcteeAvg); }
public ReportModel GetReport(int batchId, int indcuteeId) { List <DateTime> batchDateList = db.BatchDates.Where(d => d.BatchID == batchId && d.BatchDate <= DateTime.Now) .OrderBy(n => n.BatchDate) .Select(n => n.BatchDate).ToList(); List <InducteeModel> inducteesList = db.Inductee.Where(m => m.BatchID == batchId).ToList(); InducteeModel selectedInductee = indcuteeId > 0 ? inducteesList.Find(n => n.Id == indcuteeId) : null; decimal batchSum = 0.0M; ReportModel reportModel = new ReportModel() { TrainerName = TrainerName(batchId), BatchId = batchId, InducteeId = indcuteeId, NumberofInductees = inducteesList.Count, InducteeName = selectedInductee != null ? selectedInductee.Name : "", FeedBacks = new List <ReportFeedbackModel>() }; foreach (InducteeModel inductee in inducteesList) { batchSum += GetInducteeFeedbackAverage(batchDateList, selectedInductee, reportModel, inductee); } reportModel.BatchAverage = Math.Round(batchSum / reportModel.NumberofInductees, 2); return(reportModel); }
public bool Update(InducteeModel Inductee) { if (Inductee != null) { db.Entry(Inductee).State = EntityState.Modified; return(db.SaveChanges() > 0); } return(false); }
public JsonResult IsEmpID_Unique(InducteeModel Inductee) { if (Inductee.Id > 0) { return(Json(true, JsonRequestBehavior.AllowGet)); } return(IsEmpExist(Inductee.EmpId) ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(InducteeModel Inductee) { if (ModelState.IsValid) { var res = InducteeRepo.Update(Inductee); if (res == true) { ViewData["SuccessMsg"] = "Trainee updated successfully."; } else { ViewData["ErrorMsg"] = "Failed to update inductee."; } } var BatchList = BatchRepo.GetAll().OrderByDescending(b => b.Id); ViewBag.BatchList = new SelectList(BatchList, "Id", "Name", Inductee.BatchID); return(View(Inductee)); }
public ActionResult Create(InducteeModel Inductee) { try { if (ModelState.IsValid) { if (InducteeRepo.Create(Inductee)) { TrainerModel trainerModel = new TrainerModel() { Email = Inductee.Email, Name = Inductee.Name, Password = System.Web.Security.Membership.GeneratePassword(8, 6) }; int trainerid = new Trainer().Create(trainerModel); var user_type_model = new Trainer_UserType_Map_Model() { Map_Trainer_Id = trainerid, Map_UserType_Id = UserType.Trainee.GetHashCode() }; new TrainerTraineeUserMapping().Create(user_type_model); ViewData["SuccessMsg"] = "Trainee created successfully."; return(Redirect("/Inductee")); } else { ViewData["ErrorMsg"] = "Failed to create Trainee."; } } } catch (Exception) { ViewData["ErrorMsg"] = "Failed to create Trainee."; } var BatchList = BatchRepo.GetAll().OrderByDescending(b => b.Id); ViewBag.BatchList = new SelectList(BatchList, "Id", "Name"); return(View(Inductee)); }
public bool Create(InducteeModel Inductee) { db.Inductee.Add(Inductee); return(db.SaveChanges() > 0); }