public void EndExam([FromBody] ClientSheetRequest clientSheetRequest) { var sheet = repoOnSite.GetSheetBySheetId(clientSheetRequest.SheetId); var newStatus = new StatusExtension { _id = Guid.NewGuid().ToString(), ClientId = clientSheetRequest.ClientId, CreateDateTime = DateTime.Now, Status = sheet.CorrectScore >= sheet.Subject.PassScore ? "PASS" : "FAIL", }; sheet.StatusExtensions.Add(newStatus); sheet.LatestStatus = newStatus.Status; sheet.ExamDateTime = DateTime.Now; repoOnSite.UpdateSheet(sheet); //Update testreg status by sirinarin //var testreg = repoOnSite.GetTestRegisById(sheet.TestRegisID); //testreg.Status = newStatus.Status; //repoOnSite.UpdateTestRegis(testreg); if (sheet.LatestStatus == "PASS") { SyncExam(sheet); } }
public JsonResult DeliverWithinDays(string days) { var deliveries = DateFilter.getDeliveriesWithinDays(company.Deliveries.ToList(), Convert.ToInt32(days)); var routes = DateFilter.getRoutesWithinDays(company.Routes.ToList(), Convert.ToInt32(days)); Response.StatusCode = (int)HttpStatusCode.OK; List <ShipperSingleDeliveryMapViewModel> delsWithAddress = new List <ShipperSingleDeliveryMapViewModel>(); foreach (Delivery delivery in deliveries) { ShipperSingleDeliveryMapViewModel model = new ShipperSingleDeliveryMapViewModel(); model.Client = delivery.Client; model.addressString = DirectionsService.getStringFromAddress(delivery.Client.Address); model.ID = delivery.ID; string clientName = delivery.Client.FirstName + " " + delivery.Client.LastName; string currentStatus = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); string deliverByDate = delivery.DeliverBy.Value.Date.ToString(); string deliverByString = deliverByDate.Substring(0, deliverByDate.IndexOf(" ")); model.clientName = clientName; model.currentStatus = currentStatus; model.deliverBy = deliverByString; delsWithAddress.Add(model); } MapObjects result = new MapObjects(deliveries, routes, delsWithAddress, company); return(Json(result)); }
public void StartExam([FromBody] ClientSheetRequest clientSheetRequest) { var sheet = repoOnSite.GetSheetBySheetId(clientSheetRequest.SheetId); if (sheet != null) { var newStatus = new StatusExtension { _id = Guid.NewGuid().ToString(), ClientId = clientSheetRequest.ClientId, CreateDateTime = DateTime.Now, Status = "TESTING", }; var active = repoOnSite.GetLastActive().ActiveThruDateTime; if (active >= DateTime.Now.AddMinutes(sheet.Subject.ExamDuration)) { sheet.ActiveThruDateTime = DateTime.Now.AddMinutes(sheet.Subject.ExamDuration); } else { sheet.ActiveThruDateTime = active; } sheet.StatusExtensions.Add(newStatus); sheet.LatestStatus = "TESTING"; sheet.StartDateTime = DateTime.Now; repoOnSite.UpdateSheet(sheet); } }
public IActionResult Index() { var deliveries = DateFilter.getDeliveriesWithinDays(company.Deliveries.ToList(), 2); var depots = company.PickUpLocations.ToList(); List <ShipperSingleDeliveryMapViewModel> delsWithAddress = new List <ShipperSingleDeliveryMapViewModel>(); foreach (Delivery delivery in deliveries) { ShipperSingleDeliveryMapViewModel model = new ShipperSingleDeliveryMapViewModel(); model.Client = delivery.Client; model.addressString = DirectionsService.getStringFromAddress(delivery.Client.Address); model.ID = delivery.ID; string clientName = delivery.Client.FirstName + " " + delivery.Client.LastName; string currentStatus = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); string deliverByDate = delivery.DeliverBy.Value.Date.ToString(); string deliverByString = deliverByDate.Substring(0, deliverByDate.IndexOf(" ")); model.clientName = clientName; model.currentStatus = currentStatus; model.deliverBy = deliverByString; delsWithAddress.Add(model); } MapObjects objects = new MapObjects(deliveries, depots, company.Routes.ToList(), delsWithAddress, company); return(View(objects)); }
public IActionResult RouteDeliveries(int?id) { Route route = driver.Routes.Where(r => r.ID == id).FirstOrDefault(); List <Delivery> deliveries = route.Deliveries.ToList(); List <DriverDeliveryViewModel> modelsList = new List <DriverDeliveryViewModel>(); foreach (Delivery delivery in deliveries) { DriverDeliveryViewModel model = new DriverDeliveryViewModel(); model.ClientName = delivery.Client.FirstName + " " + delivery.Client.LastName; model.DeliverBy = delivery.DeliverBy; string deliverytatusString = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); if (delivery.DeliveryStatus.Status.Equals(Status.Delivered)) { DateTime deliveredDate = delivery.DeliveryStatus.DeliveredDate.Value; deliverytatusString += " " + deliveredDate.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture); } else if (delivery.DeliveryStatus.Status.Equals(Status.FailedDelivery)) { deliverytatusString = "Failed, reason: " + delivery.DeliveryStatus.ReasonFailed; } model.DeliveryStatusString = deliverytatusString; model.ID = delivery.ID; model.ItemSizeString = ItemSizeDimensionsExtension.getItemDimensionsBasedOnSize(delivery.ItemSize).ToString(); model.ItemWeight = delivery.ItemWeight; model.ClientAddress = delivery.Client.Address; modelsList.Add(model); } return(View(modelsList)); }
public IActionResult MapDelivery(int?id) { var delivery = _context.Deliveries .Include(d => d.Client) .Include(d => d.Client.Address) .Include(d => d.DeliveryStatus) .SingleOrDefault(d => d.ID == id); double locationLat = delivery.Client.Address.Lat; double locationLng = delivery.Client.Address.Lng; string clientName = delivery.Client.FirstName + " " + delivery.Client.LastName; string deliverytatusString = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); if (delivery.DeliveryStatus.Status.Equals(Status.Delivered)) { DateTime deliveredDate = delivery.DeliveryStatus.DeliveredDate.Value; deliverytatusString += " " + deliveredDate.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture); } string addressString = DirectionsService.getStringFromAddress(delivery.Client.Address); string deliverByDate = delivery.DeliverBy.Value.Date.ToString(); string deliverByString = deliverByDate.Substring(0, deliverByDate.IndexOf(" ")); DriverSingleDeliveryMapView model = new DriverSingleDeliveryMapView(locationLat, locationLng, clientName, deliverByString, deliverytatusString, addressString); return(View(model)); }
public void EndTest([FromBody] ActionSheetRequest actionSheetRequest) { var sheet = repoOnSite.GetSheetBySheetId(actionSheetRequest.sheetId); if (sheet != null) { //foreach (var item in sheet.RandomQuestions) //{ // if (item.UserAnswer != null) // { // item.UserAnswer.IsCorrect = item.Choices.Where(x => x._id == item.UserAnswer._id).FirstOrDefault().IsCorrect; // } //} //sheet.CorrectScore = sheet.RandomQuestions.Where(x => x.UserAnswer.IsCorrect.Value).Count(); //sheet.InCorrectScore = sheet.RandomQuestions.Where(x => !x.UserAnswer.IsCorrect.Value).Count(); //if (sheet.CorrectScore >= sheet.Subject.PassScore) //{ // sheet.LatestStatus = "PASS"; //} //else //{ // sheet.LatestStatus = "FAIL"; //} var newStatus = new StatusExtension { _id = Guid.NewGuid().ToString(), ClientId = "admin", CreateDateTime = DateTime.Now, //Status = sheet.LatestStatus Status = sheet.CorrectScore >= sheet.Subject.PassScore ? "PASS" : "FAIL", }; sheet.StatusExtensions.Add(newStatus); sheet.LatestStatus = newStatus.Status; sheet.ExamDateTime = DateTime.Now; repoOnSite.UpdateSheet(sheet); if (sheet.LatestStatus == "PASS") { SyncExam(sheet._id); } } }
public void Cancel([FromBody] ActionSheetRequest actionSheetRequest) { var sheet = repoOnSite.GetSheetBySheetId(actionSheetRequest.sheetId); if (sheet != null) { var newStatus = new StatusExtension { _id = Guid.NewGuid().ToString(), ClientId = "ForTest", CreateDateTime = DateTime.Now, Status = "CANCEL", }; sheet.StatusExtensions.Add(newStatus); sheet.LatestStatus = "CANCEL"; repoOnSite.UpdateSheet(sheet); } }
public bool UpdateDeliveryStatus(Delivery delivery, Status status) { Status currentDeliveryStatus = delivery.DeliveryStatus.Status; if (!StatusExtension.NextAvailableStatus(currentDeliveryStatus).Contains(status)) { return(false); } // delivery.DeliveryStatus.Status = status; var deliveryStatus = context.DeliveryStatus.SingleOrDefault(st => st.ID == delivery.DeliveryStatus.ID); deliveryStatus.Status = status; Route route = context.Routes.Where(r => r.ID == delivery.RouteID).SingleOrDefault(); bool allDelivered = true; foreach (Delivery del in route.Deliveries) { if (del.DeliveryStatus.Status != Status.Delivered) { allDelivered = false; break; } } if (status.Equals(Status.FailedDelivery)) { route.Status = RouteStatus.Pending; } else { if (allDelivered) { route.Status = RouteStatus.Completed; } else { route.Status = RouteStatus.InProgress; } } context.SaveChangesAsync(); return(true); }
public JsonResult UpdateStatus([FromBody] StatusUpdateRequest updateRequest) { Status updateStatus = StatusExtension.statusFromString(updateRequest.status); Delivery delivery = _context.Deliveries .Include(d => d.DeliveryStatus) .SingleOrDefault(d => d.ID == updateRequest.id); if (delivery == null) { Response.StatusCode = 400; return(Json(HttpStatusCode.BadRequest)); } bool statusUpdated = statusUpdateService.UpdateDeliveryStatus(delivery, updateStatus); if (!statusUpdated) { Response.StatusCode = 400; return(Json(HttpStatusCode.BadRequest)); } delivery.DeliveryStatus.Status = updateStatus; string updateStatusString = StatusExtension.DisplayName(delivery.DeliveryStatus.Status); if (updateStatus.Equals(Status.Delivered)) { DateTime deliveredDate = DateTime.Now; delivery.DeliveryStatus.DeliveredDate = deliveredDate; updateStatusString += " " + deliveredDate.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture); } Company company = _context.Companies.Include(c => c.Team.Employees).Where(c => c.ID == driver.User.CompanyID).SingleOrDefault(); notificationService.SendStatusUpdateEmailToAdminAsync(updateStatusString, delivery, company.Team.Employees.ToList()); if (updateStatus.Equals(Status.InTransit)) { notificationService.SendStatusUpdateEmailToClientAsync(updateStatus, delivery, delivery.Client); } Response.StatusCode = 200; _context.SaveChanges(); return(Json(updateStatusString)); }
public ExamSheetRespone GetSheet(string pid, string subjectCode, string clientid) { var regis = repoOnSite.GetTestRegisInfo(pid, subjectCode); if (regis.MaxCount <= regis.LatestCount) { return(null); } ExamSheet sheet = new ExamSheet(); //Get available exam sheet if haven't availble return null if (repoOnSite.GetSheetBySubjectCodeForMap(subjectCode, regis.ExamLanguage) == null) { return(new ExamSheetRespone { Message = new ViewModels.MessageRespone { Code = "1", Message = string.Format(getsheet1, subjectCode, regis.ExamLanguage).ToString() } }); } var oldsheet = repoOnSite.GetSheetByPIDAndSubjectCode(pid, subjectCode, regis.ExamLanguage); if (oldsheet.ClientId == null) { sheet = repoOnSite.GetSheetBySubjectCodeForMap(subjectCode, regis.ExamLanguage); sheet.RandomQuestions = new List <Question>(GetQuestion(sheet.RandomQuestions)); } else { if (oldsheet.LatestStatus == "FAIL") { sheet = repoOnSite.GetSheetBySubjectCodeForMap(subjectCode, regis.ExamLanguage); } else if (oldsheet.LatestStatus == "RESUME") { sheet = oldsheet; } else if (oldsheet.LatestStatus != "RESUME") { return(new ExamSheetRespone { Message = new ViewModels.MessageRespone { Code = "2", Message = getsheet2 } }); } else if (oldsheet.LatestStatus == "PASS") { return(new ExamSheetRespone { Message = new ViewModels.MessageRespone { Code = "3", Message = getsheet3 } }); } } if (sheet.LatestStatus != "RESUME") { int testCount = regis.LatestCount + 1; sheet.TestCount = testCount; regis.LatestCount = testCount; } sheet.TestRegisID = regis._id; sheet.PID = regis.PID; var newStatus = new StatusExtension { _id = Guid.NewGuid().ToString(), ClientId = clientid, CreateDateTime = DateTime.Now, Status = "Ready", }; if (sheet.StatusExtensions == null) { sheet.StatusExtensions = new List <StatusExtension>(); sheet.StatusExtensions.Add(newStatus); } else { sheet.StatusExtensions.Add(newStatus); } sheet.ClientId = clientid; sheet.LatestStatus = "Ready"; repoOnSite.UpdateSheet(sheet); repoOnSite.UpdateTestRegis(regis); var activeInfo = repoOnSite.GetLastActive(); var result = new ExamSheetRespone { _id = sheet._id, Title = regis.Title, FirstName = regis.FirstName, LastName = regis.LastName, PID = regis.PID, ExamNumber = regis.ExamNumber, SubjectCode = sheet.Subject.SubjectCode, SubjectName = sheet.Subject.SubjectName, IsEReadiness = sheet.Subject.IsEReadiness, ContentLanguage = sheet.Subject.ContentLanguage, TestCount = sheet.TestCount, LastedStatus = sheet.LatestStatus, PassScore = sheet.Subject.PassScore, CorrectScore = 0, InCorrectScore = 0, ExamDuration = sheet.Subject.ExamDuration, ReviewDuration = sheet.ReviewDuration, ActiveThruDateTime = activeInfo.ActiveThruDateTime, ClientId = clientid, Questions = sheet.RandomQuestions.Select(q => new Question { _id = q._id, QuestionNumber = q.QuestionNumber, IsAllowRandomChoice = q.IsAllowRandomChoice, Detail = q.Detail, GroupId = q.GroupId, //UserAnswer = q.UserAnswer == null ? new Choice() : //new Choice //{ // _id = q.UserAnswer._id, // Detail = q.UserAnswer.Detail, // IsCorrect = q.UserAnswer.IsCorrect.Value, //}, UserAnswer = q.UserAnswer == null ? null : new Choice { _id = q.UserAnswer._id, Detail = q.UserAnswer.Detail, IsCorrect = q.UserAnswer.IsCorrect.Value, }, Choices = q.Choices.Select(c => new Choice { _id = c._id, Detail = c.Detail, IsCorrect = null, }).ToList(), }).ToList(), Message = new MessageRespone { Code = "0", Message = getsheet0 } }; return(result); }
public ResultRespone SendExam(string sheetId, string clientid) { var sheet = repoOnSite.GetSheetBySheetId(sheetId); if (sheet != null) { foreach (var item in sheet.RandomQuestions) { if (item.UserAnswer != null) { item.UserAnswer.IsCorrect = item.Choices.Where(x => x._id == item.UserAnswer._id).FirstOrDefault().IsCorrect; } } //sheet.CorrectScore = sheet.RandomQuestions.Where(x => x.UserAnswer.IsCorrect.Value).Count(); sheet.CorrectScore = sheet.RandomQuestions.Where(x => x.UserAnswer != null && x.UserAnswer.IsCorrect.Value).Count(); //sheet.InCorrectScore = sheet.RandomQuestions.Where(x => !x.UserAnswer.IsCorrect.Value).Count(); sheet.InCorrectScore = sheet.RandomQuestions.Count() - sheet.CorrectScore; var newStatus = new StatusExtension { _id = Guid.NewGuid().ToString(), ClientId = clientid, CreateDateTime = DateTime.Now, Status = "DONE" }; sheet.StatusExtensions.Add(newStatus); sheet.LatestStatus = newStatus.Status; sheet.DoneDateTime = DateTime.Now; repoOnSite.UpdateSheet(sheet); var testregis = repoOnSite.GetTestRegisById(sheet.TestRegisID); ResultRespone result = new ResultRespone() { //IsShowAnswer = repoOnSite.GetCenter().IsShowAnswer, IsShowAnswer = true, ExamSheetRespones = new ExamSheetRespone() { _id = sheet._id, Title = testregis.Title, FirstName = testregis.FirstName, LastName = testregis.LastName, PID = testregis.PID, ExamNumber = testregis.ExamNumber, SubjectCode = sheet.Subject.SubjectCode, SubjectName = sheet.Subject.SubjectName, IsEReadiness = sheet.Subject.IsEReadiness, ContentLanguage = sheet.Subject.ContentLanguage, TestCount = sheet.TestCount, LastedStatus = sheet.LatestStatus, PassScore = sheet.Subject.PassScore, CorrectScore = sheet.CorrectScore, InCorrectScore = sheet.InCorrectScore, ExamDuration = sheet.Subject.ExamDuration, ReviewDuration = sheet.ReviewDuration, ActiveThruDateTime = sheet.ActiveThruDateTime.Value, ClientId = clientid, Questions = sheet.RandomQuestions.Select(q => new Question { _id = q._id, QuestionNumber = q.QuestionNumber, IsAllowRandomChoice = q.IsAllowRandomChoice, Detail = q.Detail, GroupId = q.GroupId, //UserAnswer = q.UserAnswer == null ? new Choice() : //new Choice //{ // _id = q.UserAnswer._id, // Detail = q.UserAnswer.Detail, // IsCorrect = q.UserAnswer.IsCorrect.Value, //}, UserAnswer = q.UserAnswer == null ? null : new Choice { _id = q.UserAnswer._id, Detail = q.UserAnswer.Detail, IsCorrect = q.UserAnswer.IsCorrect.Value, }, Choices = q.Choices.Select(c => new Choice { _id = c._id, Detail = c.Detail, IsCorrect = c.IsCorrect, }).ToList(), }).ToList(), }, }; return(result); } else { return(null); } }
public void CloseExamData() { var center = repoOnSite.GetCenter(); var listSheet = repoOnSite.ListExamData(center._id).Where(x => !String.IsNullOrEmpty(x.TestRegisID)).ToList(); foreach (var sheet in listSheet) { if (sheet.LatestStatus == "DONE") { foreach (var q in sheet.RandomQuestions) { if (q.UserAnswer != null) { q.UserAnswer.IsCorrect = q.Choices.Where(x => x._id == q.UserAnswer._id).FirstOrDefault().IsCorrect; } } sheet.CorrectScore = sheet.RandomQuestions.Where(x => x.UserAnswer.IsCorrect.Value).Count(); sheet.InCorrectScore = sheet.RandomQuestions.Where(x => !x.UserAnswer.IsCorrect.Value).Count(); if (sheet.CorrectScore >= sheet.Subject.PassScore) { sheet.LatestStatus = "PASS"; } else { sheet.LatestStatus = "FAIL"; } var newStatus = new StatusExtension { _id = Guid.NewGuid().ToString(), ClientId = "admin", CreateDateTime = DateTime.Now, Status = sheet.LatestStatus }; sheet.StatusExtensions.Add(newStatus); sheet.ExamDateTime = DateTime.Now; } sheet.IsCloseExam = true; sheet.IsSync = true; } var regisList = repoOnSite.ListTestRegis(center._id).ToList(); foreach (var item in regisList) { item.IsCloseExam = true; } List <ExamSheetOnline> sheetForOnline = new List <ExamSheetOnline>(); var listReg = repoOnSite.GetTestRegisByIds(listSheet.Select(x => x.TestRegisID).ToList()); foreach (var item in listSheet) { var regis = listReg.Where(x => x._id == item.TestRegisID).FirstOrDefault(); var regisOnline = new TestRegistrationOnline { _id = regis._id, Title = regis.Title, FirstName = regis.FirstName, LastName = regis.LastName, SubjectCode = regis.SubjectCode, SubjectName = regis.SubjectName, ExamLanguage = regis.ExamLanguage, VoiceLanguage = regis.VoiceLanguage, RegDate = regis.RegDate, RegDateString = regis.RegDateString, ExpriedDate = regis.ExpriedDate, SiteId = regis.SiteId, CenterId = regis.CenterId, ForTestSystem = regis.ForTestSystem, ForPractice = regis.ForPractice, Status = regis.Status, ExamStatus = regis.ExamStatus, PID = regis.PID, ExamNumber = regis.ExamNumber, ExamPeriod = regis.ExamPeriod, AppointDate = regis.AppointDate, Email = regis.Email, Mobile = regis.Mobile, Address = regis.Address, MaxCount = regis.MaxCount, CertData = regis.CertData, LatestCount = regis.LatestCount, }; var sheet = new ExamSheetOnline { _id = item._id, Subject = item.Subject, TestReg = regisOnline, TestCount = item.TestCount, LatestStatus = item.LatestStatus, ExamDateTime = item.ExamDateTime, StatusExtensions = item.StatusExtensions, RandomQuestion = item.RandomQuestions, CenterId = item.CenterId, CorrectScore = item.CorrectScore, InCorrectScore = item.InCorrectScore, ReviewDuration = item.ReviewDuration, CreateDate = item.CreateDate, ClientId = item.ClientId }; sheetForOnline.Add(sheet); } var missTestReg = regisList.Where(x => !listSheet.Select(y => y.TestRegisID).Contains(x._id)).Select(regis => new TestRegistrationOnline() { _id = regis._id, Title = regis.Title, FirstName = regis.FirstName, LastName = regis.LastName, SubjectCode = regis.SubjectCode, SubjectName = regis.SubjectName, ExamLanguage = regis.ExamLanguage, VoiceLanguage = regis.VoiceLanguage, RegDate = regis.RegDate, RegDateString = regis.RegDateString, ExpriedDate = regis.ExpriedDate, SiteId = regis.SiteId, CenterId = regis.CenterId, ForTestSystem = regis.ForTestSystem, ForPractice = regis.ForPractice, Status = regis.Status, ExamStatus = regis.ExamStatus, PID = regis.PID, ExamNumber = regis.ExamNumber, ExamPeriod = regis.ExamPeriod, AppointDate = regis.AppointDate, Email = regis.Email, Mobile = regis.Mobile, Address = regis.Address, MaxCount = regis.MaxCount, CertData = regis.CertData, LatestCount = regis.LatestCount, }).ToList(); CloseExamRequest request = new CloseExamRequest() { ResultSheet = sheetForOnline, MissTestReg = missTestReg, }; using (var client = new WebClient()) { try { var json = Newtonsoft.Json.JsonConvert.SerializeObject(request); var dataByte = System.Text.Encoding.UTF8.GetBytes(json); client.Headers[HttpRequestHeader.ContentType] = "application/json"; dataByte = client.UploadData("http://eexamthaiex.azurewebsites.net/api/ExamSheet/UpdateExamSheetFromOnSite/", "POST", dataByte); //dataByte = client.UploadData("http://localhost:10585/api/ExamSheet/UpdateExamSheetFromOnSite/", "POST", dataByte); //update sheet repoOnSite.CloseSheet(listSheet); //update Regis repoOnSite.CloseTestRegis(regisList); } catch (Exception e) { throw new Exception(e.Message); } } }