Esempio n. 1
0
 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)
     {
     }
 }
Esempio n. 2
0
 public ActionResult Create(ClassViewModel model)
 {
     try
     {
         ViewBag.IsApproved = true;
         UnitOfWork uow = new UnitOfWork();
         if (Convert.ToInt32(model.DurationHour) < 1 && Convert.ToInt32(model.DurationMinutes) < 30)
         {
             ModelState.AddModelError("classtime-error", Resources.Resources.MsgClassDurationError);
             return(View(ReturnCreateClassView(model)));
         }
         else if (!ModelState.IsValid)
         {
             return(View(ReturnCreateClassView(model)));
         }
         else
         {
             bool record = false;
             if (model.Record == "1" && model.SessionType == 1)
             {
                 record = true;
             }
             string   dateAndTime = model.Date;
             DateTime classDate   = DateTime.ParseExact(dateAndTime, "dd/MM/yyyy", CultureInfo.InvariantCulture);
             if (Convert.ToInt32(model.DurationHour) > 0 || Convert.ToInt32(model.DurationMinutes) > 0)
             {
                 //dateAndTime = model.Date + " " + model.StartTime.Insert(model.StartTime.Length - 2, " ");
                 dateAndTime = model.Date + " " + model.ClassHour + ":" + model.ClassMinute + " " + model.ClassAMPM; //.Insert(model.StartTime.Length - 2, " ");
                 classDate   = DateTime.ParseExact(dateAndTime, "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);
             }
             //first create braincert class
             int brainCertId = 0;
             if (model.SessionType == 1)
             {
                 string classEndTime = classDate.AddHours(Convert.ToDouble(model.DurationHour)).AddMinutes(Convert.ToDouble(model.DurationMinutes)).ToString("HH:mm tt");
                 model.StartTime = classDate.ToString("hh:mm tt");
                 // only 30 minute class is allowed in trial period
                 model.ClassEndTime = classDate.AddMinutes(30).ToString("hh:mm tt"); //classEndTime;
                 brainCertId        = BrainCert.CreateBrainCertClass(model.Title, classDate.ToString("MM/dd/yyyy HH:mm"), model.StartTime, model.ClassEndTime, Convert.ToInt32(model.Record), Convert.ToInt32(model.TimeZone));
                 if (brainCertId == 0)
                 {
                     ModelState.AddModelError("error", Resources.Resources.MsgErrorTryAgain);
                     return(View(ReturnCreateClassView(model)));
                 }
             }
             decimal classDuration = Math.Round(Convert.ToInt16(model.DurationHour) + (Convert.ToInt16(model.DurationMinutes) / 60m), 2);
             Class   clsCreate     = new Class()
             {
                 ClassID          = Guid.NewGuid().ToString(),
                 Title            = model.Title,
                 ClassDate        = classDate,
                 StartTime        = model.StartTime,
                 EndTime          = model.ClassEndTime,
                 Duration         = classDuration,
                 CreationDate     = DateTime.Now,
                 Type             = model.SessionType,
                 Record           = record,
                 CreatedBy        = Session["UserId"].ToString(),
                 TeacherID        = Session["UserId"].ToString(),
                 Description      = model.Description,
                 SubjectID        = model.Subject,
                 Status           = (int)ClassStatus.Created,
                 BrainCertId      = brainCertId,
                 CreatedByStudent = false
             };
             uow.Classes.Insert(clsCreate);
             uow.Save();
             AddClassFiles(model.files, clsCreate.ClassID);
             //send to invite page in case of written class
             if (model.SessionType == (int)SessionType.Written)
             {
                 return(RedirectToAction("Invite", new { id = clsCreate.ClassID }));
             }
             ClassViewModel classView = new ClassViewModel();
             ModelState.Clear();
             ModelState.AddModelError("success", Resources.Resources.MsgClassCreatedSuccess);
             return(View(ReturnCreateClassView(classView)));
         }
     }
     catch (Exception)
     {
         return(View());
     }
 }