public void UpdateProposalStatus(string bidId, string status) { UnitOfWork uow = new UnitOfWork(); StudentProblemBid bid = uow.StudentProblemBids.GetByID(bidId); if (status == "viewed") { bid.Status = (int)BidStatus.Viewed; } else if (status == "accept") { StudentProblem problem = uow.StudentProblems.GetByID(bid.ProblemID); if (Common.UserHasCredits(problem.StudentID, (decimal)problem.HoursNeeded)) { bid.Status = (int)BidStatus.Offered; problem.Status = (int)ProblemStatus.BidAccepted; Common.AddNotification("Your proposal has been accepted by " + Session["UserName"].ToString(), "", Session["UserId"].ToString(), bid.UserID, "/bid/detail/" + bid.BidID, (int)NotificationType.Bid); } else { ModelState.AddModelError("error", Resources.Resources.MsgNoBalance); } } else if (status == "decline") { bid.Status = (int)BidStatus.Declined; Common.AddNotification("Your proposal has been declined.", "", Session["UserId"].ToString(), bid.UserID, "/bid/detail/" + bid.BidID, (int)NotificationType.Bid); } uow.Save(); uow.Dispose(); }
public void UpdateClassStatus(string bidId, string status) { try { string message = ""; string userId = Session["UserId"].ToString(); string userName = Session["UserName"].ToString(); UnitOfWork uow = new UnitOfWork(); StudentProblemBid bid = uow.StudentProblemBids.GetByID(bidId); StudentProblem problem = uow.StudentProblems.GetByID(bid.ProblemID); Class classDetail = uow.Classes.Get(x => x.ProblemID == problem.ProblemID).FirstOrDefault(); if (status == "accept") { if (Common.UserHasCredits(problem.StudentID, (decimal)problem.HoursNeeded)) { bid.Status = (int)BidStatus.Accepted; classDetail.Status = (int)ClassStatus.OfferAccepted; Common.AddNotification("Your offer is accepted by " + userName, "", userId, problem.StudentID, "/problem/proposal/" + bid.BidID, (int)NotificationType.Class); message = "Your offer is accepted by "; int braincertClassId = 0; if (classDetail.Type == (int)SessionType.Live) { braincertClassId = Convert.ToInt32(BrainCert.CreateBrainCertClass(classDetail.Title, classDetail.ClassDate.ToString("MM/dd/yyyy HH:mm"), classDetail.StartTime, classDetail.EndTime, Convert.ToInt32(classDetail.Record), Convert.ToInt32(classDetail.TimeZone))); classDetail.BrainCertId = braincertClassId; } DeductStudentCredits(problem.StudentID, classDetail.ClassID, (decimal)classDetail.Duration); } else { ModelState.AddModelError("error", Resources.Resources.MsgNoBalance); } } else if (status == "decline") { bid.Status = (int)BidStatus.Declined; classDetail.Status = (int)ClassStatus.OfferDeclined; Common.AddNotification("Your offer is declined by " + userName, "", userId, problem.StudentID, "/problem/proposal/" + bid.BidID, (int)NotificationType.Class); message = "Your offer is declined by "; } Message msg = new Message { BidID = bid.BidID, FromUser = userId, ToUser = bid.UserID, CreationDate = DateTime.Now, Message1 = message + userName, Status = 1, }; uow.Messages.Insert(msg); uow.Save(); uow.Dispose(); } catch (Exception ex) { } }
public ActionResult Problems(ProblemsModel model, HttpPostedFileBase file) { UnitOfWork uow = new UnitOfWork(); model.Subjects = new SelectList(uow.Subjects.Get(), "SubjectID", "SubjectName"); model.SessionTypes = GetSessionTypess(); if (!ModelState.IsValid) { model.Problems = uow.UserRepository.GetProblemsByStudentId(Session["UserId"].ToString()); ModelState.AddModelError("error", Resources.Resources.InvalidInfo); return(View(model)); } string fileName = null; if (file != null) { fileName = Guid.NewGuid().ToString() + Path.GetFileName(file.FileName); string path = Path.Combine(Server.MapPath("~/Content/images/"), fileName); file.SaveAs(path); //byte[] bytes; //using (BinaryReader br = new BinaryReader(file.InputStream)) //{ // bytes = br.ReadBytes(file.ContentLength); //} //fileName = bytes; } StudentProblem problem = new StudentProblem { ProblemID = Guid.NewGuid().ToString(), StudentID = Session["UserId"].ToString(), SubjectID = model.Subject, CreationDate = DateTime.Now, Description = model.ProblemDescription, HoursNeeded = model.HoursNeeded, Type = model.Type, FileName = fileName, ExpireDate = DateTime.ParseExact(model.DeadLine, "dd/MM/yyyy", CultureInfo.InvariantCulture) // need to add datetime datepicker }; uow.StudentProblems.Insert(problem); uow.Save(); model.Problems = uow.UserRepository.GetProblemsByStudentId(Session["UserId"].ToString()); ModelState.AddModelError("success", Resources.Resources.MsgProblemSubmitedSuccessfully); return(View(model)); }
public ActionResult CreateProblem(ProblemsModel model, List <HttpPostedFileBase> files) { Common common = new Common(); UnitOfWork uow = new UnitOfWork(); List <TeacherSubject> subjects = uow.TeacherRepository.GetSubjects(model.TeacherID); model.Subjects = new SelectList(uow.Subjects.Get(), "SubjectID", "SubjectName"); model.SessionTypes = GetSessionTypess(); model.DurationHourList = new SelectList(common.GetDurationHours()); model.DurationMinuteList = new SelectList(common.GetMinutes()); if (Convert.ToInt32(model.DurationHour) < 1 && Convert.ToInt32(model.DurationMinutes) < 30) { ModelState.AddModelError("classtime-error", Resources.Resources.MsgClassDurationError); return(View(model)); } else if (!ModelState.IsValid) { if (!string.IsNullOrEmpty(model.TeacherID)) { User selectedTeacher = uow.Users.GetByID(model.TeacherID); ViewBag.TeacherName = selectedTeacher.FirstName + " " + selectedTeacher.LastName; } //ModelState.AddModelError("error", Resources.Resources.InvalidInfo); return(View(model)); } string userId = Session["UserId"].ToString(); if (Common.UserHasCredits(userId, model.HoursNeeded)) { decimal classDuration = Math.Round(Convert.ToInt16(model.DurationHour) + (Convert.ToInt16(model.DurationMinutes) / 60m), 2); StudentProblem problem = new StudentProblem { ProblemID = Guid.NewGuid().ToString(), StudentID = Session["UserId"].ToString(), SubjectID = model.Subject, CreationDate = DateTime.Now, Description = model.ProblemDescription, HoursNeeded = classDuration, Type = model.Type, //FileName = fileName, TeacherID = model.TeacherID, Status = model.TeacherID != null ? (int)ProblemStatus.TeacherSelected : (int)ProblemStatus.Created, ExpireDate = DateTime.ParseExact(model.DeadLine, "dd/MM/yyyy", CultureInfo.InvariantCulture) // need to add datetime datepicker }; uow.StudentProblems.Insert(problem); //save problem files(s) in uploads folder if (files != null && files.Count > 0) { foreach (var file in files) { if (file != null) { string fileName = null; //fileName = Guid.NewGuid().ToString() + Path.GetFileName(file.FileName); fileName = Path.GetFileName(file.FileName); string path = Path.Combine(Server.MapPath("~/Uploads/QuestionFiles/"), fileName); if (System.IO.File.Exists(path)) { string[] fileNameSplit = fileName.Split('.'); if (fileNameSplit.Count() > 1) { fileName = fileName.Split('.')[0] + "_2." + fileName.Split('.')[1]; } else { fileName = fileName + "_2"; } path = Path.Combine(Server.MapPath("~/Uploads/QuestionFiles/"), fileName); } file.SaveAs(path); //save problem files(s) in database StudentProblemFile problemFile = new StudentProblemFile { ProblemID = problem.ProblemID, FileName = fileName, CreationDate = DateTime.Now, UserID = userId }; uow.StudentProblemFiles.Insert(problemFile); } } } uow.Save(); //add notification if teacher is selected if (!string.IsNullOrEmpty(model.TeacherID)) { Common.AddNotification(Session["UserName"] + " asked you a question", "", Session["UserId"].ToString(), model.TeacherID, "/tutor/writeproposal?q=" + problem.ProblemID, (int)NotificationType.Question); } //end ModelState.AddModelError("success", Resources.Resources.MsgProblemSubmitedSuccessfully); return(View(model)); } else { model.SessionTypes = GetSessionTypess(); model.DurationMinuteList = new SelectList(common.GetMinutes()); model.DurationHourList = new SelectList(common.GetDurationHours()); model.Subjects = new SelectList(uow.Subjects.Get(), "SubjectID", "SubjectName"); ModelState.AddModelError("error", Resources.Resources.MsgNoBalance); return(View(model)); } }