public object listAllqcustom(string id) { var qcustom = _context.TestQCustoms.Include(i => i.Question).Where(w => 1 == 1); var tID = NumUtil.ParseInteger(id); if (tID > 0) { qcustom = qcustom.Where(w => w.TestID == tID); } var questioncnt = qcustom.Where(w => w.Question.QuestionType != QuestionType.ReadingText && w.Question.QuestionType != QuestionType.MultipleMatching).Count(); questioncnt += _context.Questions.Where(w => w.QuestionParentID.HasValue && qcustom.Select(s => s.Question.ID).Contains(w.QuestionParentID.Value)).Count(); return(CreatedAtAction(nameof(listAlltest), new { data = qcustom.Select(s => new { id = s.ID, testid = s.TestID, order = s.Order, questionid = s.QuestionID, questionth = s.Question.QuestionTh, questionen = s.Question.QuestionEn, questionlevel = s.Question.QuestionLevel.toQuestionLevelName(), questiontype = s.Question.QuestionType.toQuestionTypeMin2(), childcnt = _context.Questions.Where(w => w.QuestionParentID == s.QuestionID).Count(), create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderBy(o => o.order).ToArray(), questioncnt = questioncnt, })); }
public JsonResult GetDeliveryDetails(string DeliveryID) { List <CMSDeliveryDetailWModels> SyncDatas = new List <CMSDeliveryDetailWModels>(); var cmsService = new CMSService(); int Delivery_ID = NumUtil.ParseInteger(DeliveryID); var cri = new DeliveryCriteria(); cri.Delivery_ID = Delivery_ID; var result = cmsService.GetCMSDelivery(cri); if (result.Code == ReturnCode.SUCCESS) { var deliverys = result.Object as List <CMS_Delivery>; if (deliverys != null && deliverys.Count() == 1) { var delivery = deliverys.FirstOrDefault(); foreach (var row in delivery.CMS_Delivery_Detail) { var lrow = new CMSDeliveryDetailWModels(); lrow.CMS_Delivery_Detail_ID = row.CMS_Delivery_Detail_ID; if (!string.IsNullOrEmpty(row.Product_Code)) { lrow.Product_ID = 1; //remove after improve code in mobile lrow.Product_Code = row.Product_Code; lrow.Product_Name = ""; } SyncDatas.Add(lrow); } } } return(Json(SyncDatas, JsonRequestBehavior.AllowGet)); }
public IActionResult Index(PointConditionDTO model) { if (!_loginServices.isInAdminRoles(this.GetRoles())) { return(RedirectToAction("Login", "Accounts")); } int pageno = 1; if (this.RouteData.Values["pno"] != null) { pageno = NumUtil.ParseInteger(this.RouteData.Values["pno"].ToString()); if (pageno == 0) { pageno = 1; } } int skipRows = (pageno - 1) * 100; model.PointConditions = this._context.PointConditions .Include(s => s.PointConditionProducts) .OrderBy(c => c.TransacionTypeID).ThenBy(o => o.OutletCode).ThenBy(o => o.ConditionCode); ViewBag.ItemCount = model.PointConditions.Count(); ViewBag.PageLength = (ViewBag.ItemCount / 100); if (ViewBag.ItemCount % 100 > 0) { ViewBag.PageLength += 1; } ViewBag.PageNo = pageno; model.PointConditions = model.PointConditions.Skip(skipRows).Take(100); return(View("Condition", model)); }
public async Task <IActionResult> Update(int?id, string tab, string code) { if (!_loginServices.isInAdminRoles(this.GetRoles())) { return(RedirectToAction("Login", "Accounts")); } var model = this._context.Privileges .Include(i => i.Merchant) .Include(i => i.PrivilegeImages) .Include(i => i.Merchant.MerchantCategories) .Include(i => i.PrivilegeCustomerClasses) .Include(i => i.PrivilegeCodes) .Where(w => w.PrivilegeID == id).FirstOrDefault(); if (model != null) { if (model.CustomerClassList.Count <= 0) { model.PrivilegeCustomerClasses = new List <PrivilegeCustomerClass>(); } int pageno = 1; if (this.RouteData.Values["pno"] != null) { pageno = NumUtil.ParseInteger(this.RouteData.Values["pno"].ToString()); if (pageno == 0) { pageno = 1; } } var modelcode = new ModelReportBaseDTO(); modelcode.search_code = code; modelcode.pno = pageno; modelcode.pmax = 10; modelcode.search_privilege = model.PrivilegeID; var codes = await _priRepo.ListCode(modelcode); ViewBag.ItemCount = modelcode.totalrow; ViewBag.PageLength = (ViewBag.ItemCount / 10); if (ViewBag.ItemCount % 10 > 0) { ViewBag.PageLength += 1; } ViewBag.PageNo = pageno; model.PrivilegeCodes = codes; //if (model.PrivilegeCodeList.Count <= 0) // model.PrivilegeCodes = new Collection<PrivilegeCode>() { new PrivilegeCode() { Status = StatusType.Active } }; model.sDate = DateUtil.ToDisplayDate(model.StartDate); model.eDate = DateUtil.ToDisplayDate(model.EndDate); model.tab = tab; } ViewBag.ListMerchant = this._context.Merchants.Include(i => i.MerchantCategories).OrderBy(o => o.MerchantName); ViewBag.ListType = this._context.MerchantCategories.Where(w => w.Status == StatusType.Active).OrderBy(o => o.Index); ViewBag.TotalQuantity = this._context.Redeems.Where(w => w.PrivilegeID == id).Count(); ViewBag.ListCustomerClass = this._context.CustomerClasses; return(View("PrivilegeInfo", model)); }
public object getsendresultsetup(string group_searh, string subject_search) { var groupid = NumUtil.ParseInteger(group_searh); var subjectid = NumUtil.ParseInteger(subject_search); var setup = _context.SendResultSetups.Where(w => w.SubjectGroupID == groupid & w.SubjectID == subjectid).Select(s => new { result = ResultCode.Success, message = ResultMessage.Success, id = s.ID, group = s.SubjectGroup.Name, groupid = s.SubjectGroupID, subject = s.Subject.Name, subjectid = s.SubjectID, other = s.Other, sendbyemail = s.SendByEmail, sendbypost = s.SendByPost, description = s.Description, create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).FirstOrDefault(); if (setup != null) { return(setup); } return(CreatedAtAction(nameof(getsendresultsetup), new { result = ResultCode.DataHasNotFound, message = ResultMessage.DataHasNotFound })); }
public object listAllqrandom(string id) { var qrandom = _context.TestQRandoms.Include(i => i.SubjectSub).Where(w => 1 == 1); var tID = NumUtil.ParseInteger(id); if (tID > 0) { qrandom = qrandom.Where(w => w.TestID == tID); } return(qrandom.Select(s => new { id = s.ID, questiontype = s.QuestionType.toQuestionTypeMin(), questiontypeid = s.QuestionType, testid = s.TestID, subid = s.SubjectSubID, sub = s.SubjectSub.Name, veryeasy = s.VeryEasy, easy = s.Easy, mid = s.Mid, hard = s.Hard, veryhard = s.VeryHard, create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderBy(o => o.questiontypeid).ThenBy(o => o.sub).ToArray() ); }
public IActionResult Index(PrivilegeDTO model) { if (!_loginServices.isInAdminRoles(this.GetRoles())) { return(RedirectToAction("Login", "Accounts")); } int pageno = 1; if (this.RouteData.Values["pno"] != null) { pageno = NumUtil.ParseInteger(this.RouteData.Values["pno"].ToString()); if (pageno == 0) { pageno = 1; } } int skipRows = (pageno - 1) * 25; model.Privileges = this._context.Privileges .Include(s => s.Merchant) .Include(s => s.MerchantCategory) .Include(s => s.Redeems) .OrderBy(c => c.Index).ThenByDescending(o => o.PrivilegeID); if (model.CategoryID.HasValue) { model.Privileges = model.Privileges.Where(w => w.CategoryID == model.CategoryID); } if (!string.IsNullOrEmpty(model.search_text)) { var text = model.search_text.ToLower(); model.Privileges = model.Privileges .Where(c => (!string.IsNullOrEmpty(c.PrivilegeName) && c.PrivilegeName.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Merchant.MerchantName) && c.Merchant.MerchantName.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Allowable_Outlet) && c.Allowable_Outlet.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.PrivilegeCondition) && c.PrivilegeCondition.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.PrivilegeDesc) && c.PrivilegeDesc.ToLower().Contains(text)) ); } ViewBag.ItemCount = model.Privileges.Count(); ViewBag.PageLength = (ViewBag.ItemCount / 25); if (ViewBag.ItemCount % 25 > 0) { ViewBag.PageLength += 1; } ViewBag.PageNo = pageno; model.Privileges = model.Privileges.Skip(skipRows).Take(25); model.MerchantCategorys = this._context.MerchantCategories.Where(w => w.Status == StatusType.Active).OrderBy(o => o.Index); return(View("Privilege", model)); }
public object listlog(string student_search, string from_search, string to_search, int pageno = 1) { var id = NumUtil.ParseInteger(student_search); var logs = _context.LoginStudentHistorys.Include(i => i.Student).Where(w => 1 == 1); if (id > 0) { logs = logs.Where(w => w.StudentID == id); } if (!string.IsNullOrEmpty(from_search)) { var date = DateUtil.ToDate(from_search).Value.Date; logs = logs.Where(w => w.Update_On.Value.Date >= date); } if (!string.IsNullOrEmpty(to_search)) { var date = DateUtil.ToDate(to_search).Value.Date; logs = logs.Where(w => w.Update_On.Value.Date <= date); } int skipRows = (pageno - 1) * 25; var itemcnt = logs.Count(); var pagelen = itemcnt / 25; if (itemcnt % 25 > 0) { pagelen += 1; } return(CreatedAtAction(nameof(listlog), new { data = logs.Select(s => new { id = s.ID, prefix = s.Student.Prefix.toPrefixName(), firstname = s.Student.FirstName, lastname = s.Student.LastName, firstnameen = s.Student.FirstNameEn, lastnameen = s.Student.LastNameEn, authtype = s.AuthType.toAuthType(), create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, date = s.Update_On, }).OrderByDescending(o => o.date).Skip(skipRows).Take(25).ToArray(), pagelen = pagelen, itemcnt = itemcnt, }));; }
public ActionResult GlobalLookup(GlobalLookupViewModel model, ServiceResult msgresult) { var uService = new UserService(User.Identity.GetUserId()); var prole = uService.ValidatePageRole(User.Identity.GetUserId(), Page_Code.P0014); if (prole == null) { return(RedirectToAction("ErrorPage", "Account", new ErrorViewModel() { Message = Resource.Message_Access_Denied })); } if (prole.View == null || prole.View == false) { return(RedirectToAction("ErrorPage", "Account", new ErrorViewModel() { Message = Resource.Message_Access_Denied })); } ModelState.Clear(); if (model.operation == Operation.D) { return(GlobalLookup(model)); } model.result = msgresult; model.Modify = prole.Modify; model.View = prole.View; var cService = new ComboService(); model.cGlobalDefList = cService.LstLookupDef(); if (model.cGlobalDefList.Count > 0 && !model.search_Def_ID.HasValue) { model.search_Def_ID = NumUtil.ParseInteger(model.cGlobalDefList[0].Value); } if (model.search_Def_ID.HasValue) { var gService = new GlobalLookupService(); var cri = new GlobalLookupCriteria(); cri.Def_ID = model.search_Def_ID; var result = gService.GetGlobalLookupData(cri); if (result.Code == ReturnCode.SUCCESS) { model.GlobalDataList = result.Object as List <Global_Lookup_Data>; } } return(View(model)); }
public object listAllsubject(string text_search, string status_search, string group_search) { var subject = _context.Subjects.Include(i => i.SubjectGroup).Where(w => 1 == 1); if (!string.IsNullOrEmpty(status_search)) { subject = subject.Where(w => w.Status == status_search.toStatus()); } if (!string.IsNullOrEmpty(group_search)) { var groupID = NumUtil.ParseInteger(group_search); if (groupID > 0) { subject = subject.Where(w => w.SubjectGroupID == groupID); } } var subjects = new List <Subject>(); if (!string.IsNullOrEmpty(text_search)) { var text_splits = text_search.Split(",", StringSplitOptions.RemoveEmptyEntries); foreach (var text_split in text_splits) { if (!string.IsNullOrEmpty(text_split)) { var text = text_split.Trim(); subjects.AddRange(subject.Where(w => w.Name.Contains(text))); } } subjects = subjects.Distinct().ToList(); } else { subjects = subject.ToList(); } return(subjects.Select(s => new { id = s.ID, name = s.Name, description = s.Description, order = s.Order, status = s.Status.toStatusName(), group = s.SubjectGroup.Name, create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderBy(o => o.group).ThenBy(o2 => o2.order).ToArray()); }
public object chooseqcustom(string choose, string tid, string update_by) { if (choose == null) { return(CreatedAtAction(nameof(chooseqcustom), new { result = ResultCode.Success, message = ResultMessage.Success })); } var chs = choose.Split(";", StringSplitOptions.RemoveEmptyEntries); foreach (var ch in chs) { if (!string.IsNullOrEmpty(ch)) { var qid = NumUtil.ParseInteger(ch); var tqcustom = new TestQCustom(); tqcustom.QuestionID = qid; tqcustom.TestID = NumUtil.ParseInteger(tid); tqcustom.Create_On = DateUtil.Now(); tqcustom.Update_On = DateUtil.Now(); tqcustom.Update_By = update_by; tqcustom.Create_By = update_by; _context.TestQCustoms.Add(tqcustom); } } _context.SaveChanges(); var testID = NumUtil.ParseInteger(tid); var i = 1; var questions = _context.TestQCustoms.Where(w => w.TestID == testID).OrderBy(w => w.QuestionID); foreach (var q in questions) { q.Update_On = DateUtil.Now(); q.Update_By = update_by; q.Order = i; i++; } var test = _context.Tests.Where(w => w.ID == testID).FirstOrDefault(); if (test != null) { test.Update_On = DateUtil.Now(); test.Update_By = update_by; test.QuestionCnt = i - 1; } _context.SaveChanges(); return(CreatedAtAction(nameof(chooseqcustom), new { result = ResultCode.Success, message = ResultMessage.Success })); }
public IActionResult Index(MerchantDTO model) { //var Cookies = Request.Cookies; if (!_loginServices.isInAdminRoles(this.GetRoles())) { return(RedirectToAction("Login", "Accounts")); } int pageno = 1; if (this.RouteData.Values["pno"] != null) { pageno = NumUtil.ParseInteger(this.RouteData.Values["pno"].ToString()); if (pageno == 0) { pageno = 1; } } int skipRows = (pageno - 1) * 25; model.Merchants = this._context.Merchants.OrderBy(c => c.MerchantName); if (model.CategoryID.HasValue) { model.Merchants = model.Merchants.Where(w => w.CategoryID == model.CategoryID); } if (!string.IsNullOrEmpty(model.search_text)) { var text = model.search_text.ToLower(); model.Merchants = model.Merchants .Where(c => (!string.IsNullOrEmpty(c.MerchantName) && c.MerchantName.ToLower().Contains(text)) ); } ViewBag.ItemCount = model.Merchants.Count(); ViewBag.PageLength = (ViewBag.ItemCount / 25); if (ViewBag.ItemCount % 25 > 0) { ViewBag.PageLength += 1; } ViewBag.PageNo = pageno; model.Merchants = model.Merchants.Skip(skipRows).Take(25); model.MerchantCategorys = this._context.MerchantCategories.Where(w => w.Status == StatusType.Active).OrderBy(o => o.Index); return(View("Merchant", model)); }
public JsonResult SyncDownDeliveryByRecord(string DeliveryID) { var SyncData = new CMSDeliveryWModels(); var cmsService = new MobileService(); var cri = new MobileCri(); cri.Delivery_ID = NumUtil.ParseInteger(DeliveryID); cri.Sync_Not_Completed = true; cri.Is_Active = true; var result = cmsService.GetCMSDelivery(cri); if (result.Code == ReturnCode.SUCCESS) { var DOlist = result.Object as List <CMS_Delivery>; if (DOlist != null && DOlist.Count > 0) { var d = DOlist.FirstOrDefault(); if (d != null) { SyncData.Delivery_ID = d.Delivery_ID; SyncData.Delivery_Order_No = d.Delivery_Order_No; SyncData.Update_On = DateUtil.ToDisplayDateTime(d.Update_On); SyncData.Record_Status = d.Record_Status; List <CMSDeliveryDetailWModels> details = new List <CMSDeliveryDetailWModels>(); foreach (var row2 in d.CMS_Delivery_Detail as List <CMS_Delivery_Detail> ) { var detail = new CMSDeliveryDetailWModels(); detail.CMS_Delivery_Detail_ID = row2.CMS_Delivery_Detail_ID; if (!string.IsNullOrEmpty(row2.Product_Code)) { detail.Product_ID = 1; //remove after improve code in mobile detail.Product_Code = row2.Product_Code.Trim(); detail.Product_Name = ""; } detail.No_Of_Containers = row2.No_Of_Containers.HasValue ? row2.No_Of_Containers.Value : 1; details.Add(detail); } SyncData.DeliveryDetail = details; } } } return(Json(SyncData, JsonRequestBehavior.AllowGet)); }
public object uploadwalkin([FromBody] JsonElement json) { var model = JsonConvert.DeserializeObject <ChooseDTO>(json.GetRawText()); var examidint = NumUtil.ParseInteger(model.examid); var chs = model.choose.Split(";"); foreach (var ch in chs) { if (!string.IsNullOrEmpty(ch)) { var studentid = NumUtil.ParseInteger(ch); var reged = _context.ExamRegisters.Where(w => w.StudentID == studentid & w.ExamID == examidint).FirstOrDefault(); if (reged == null) { var register = new ExamRegister(); register.StudentID = studentid; register.ExamID = NumUtil.ParseInteger(model.examid); register.ExamRegisterType = ExamRegisterType.WalkIn; register.Create_On = DateUtil.Now(); register.Update_On = DateUtil.Now(); register.Create_By = model.update_by; register.Update_By = model.update_by; _context.ExamRegisters.Add(register); } } } _context.SaveChanges(); var exam = _context.Exams.Where(w => w.ID == examidint).FirstOrDefault(); if (exam != null) { exam.RegisterCnt = _context.ExamRegisters.Where(w => w.ExamID == examidint).Count(); exam.Update_On = DateUtil.Now(); exam.Update_By = model.update_by; _context.SaveChanges(); return(CreatedAtAction(nameof(upload), new { result = ResultCode.Success, message = ResultMessage.Success, registercnt = exam.RegisterCnt })); } return(CreatedAtAction(nameof(uploadwalkin), new { result = ResultCode.Success, message = ResultMessage.Success })); }
public object listActivetest(string group_search, string subject_search) { var test = _context.Tests.Include(i => i.Subject).Include(i => i.Subject.SubjectGroup).Where(w => w.Status == StatusType.Active & w.ApprovalStatus == TestApprovalType.Approved); if (!string.IsNullOrEmpty(subject_search)) { var subjectID = NumUtil.ParseInteger(subject_search); if (subjectID > 0) { test = test.Where(w => w.SubjectID == subjectID); } } if (!string.IsNullOrEmpty(group_search)) { var groupID = NumUtil.ParseInteger(group_search); if (groupID > 0) { test = test.Where(w => w.Subject.SubjectGroupID == groupID); } } if (test != null) { return(test.Select(s => new { id = s.ID, name = s.Name, status = s.Status.toStatusName(), subject = s.Subject.Name, subjectindex = s.Subject.Order, group = s.Subject.SubjectGroup.Name, testcode = s.TestCode, approvalstatus = s.ApprovalStatus, approvalstatusname = s.ApprovalStatus.toTestApprovalStatusName(), create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderBy(o => o.group).ThenBy(o2 => o2.subjectindex).ThenBy(o3 => o3.name).ToArray()); } return(CreatedAtAction(nameof(listActivetest), new { result = ResultCode.DataHasNotFound, message = ResultMessage.DataHasNotFound })); }
public object listAllregistered(string exam_search, int pageno = 1) { var examid = NumUtil.ParseInteger(exam_search); var exam = _context.ExamRegisters.Include(i => i.Exam).Where(w => w.ExamID == examid); int skipRows = (pageno - 1) * 200; var itemcnt = exam.Count(); var pagelen = itemcnt / 200; if (itemcnt % 200 > 0) { pagelen += 1; } return(CreatedAtAction(nameof(listAllexam), new { data = exam.Select(s => new { id = s.ID, prefix = s.Student.Prefix.toPrefixName(), firstname = s.Student.FirstName, lastname = s.Student.LastName, firstnameen = s.Student.FirstNameEn, lastnameen = s.Student.LastNameEn, studentcode = s.Student.StudentCode, course = s.Student.Course.toCourseName(), faculty = s.Student.Faculty, email = s.Student.Email, phone = s.Student.Phone, idcard = s.Student.IDCard, examregistertype = s.ExamRegisterType.toExamRegisterType(), inexam = _context.TestResultStudents.Where(w => w.ExamID == examid & w.StudentID == s.StudentID).FirstOrDefault() != null ? true : false, create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderBy(o => o.studentcode).Skip(skipRows).Take(200).ToArray(), pagelen = pagelen, itemcnt = itemcnt, })); }
public async Task <IActionResult> SendDeleteAccount(string idcard) { var customers = _context.Customers.Include(i => i.User).Where(w => w.IDCard == idcard); if (_conf.SendEmail == true) { foreach (var customer in customers) { GetCustomerClass(customer); } this._context.SaveChanges(); var codes = new List <string>(); foreach (var customer in customers) { var accode = new AccountCode(); accode.Code = this.CreateAccountCode(); accode.Create_On = DateUtil.Now(); accode.Create_By = customer.User.UserName; accode.CustomerID = customer.ID; accode.Status = StatusType.Active; codes.Add(accode.Code); this._context.AccountCodes.Add(accode); var point = this._context.CustomerPoints.Where(w => w.CustomerID == customer.ID).Sum(s => s.Point); var redeempoint = this._context.Redeems.Where(w => w.CustomerID == customer.ID).Sum(s => s.Point); var totalPoint = point - redeempoint; customer.Point = NumUtil.ParseInteger(totalPoint); customer.CustomerClass = _context.CustomerClasses.Where(w => w.ID == customer.CustomerClassID).FirstOrDefault(); } this._context.SaveChanges(); await MailDeleteAccount(customers, codes); } var model = new List <string>(); model = customers.Select(s => s.Email).ToList(); return(View(model)); }
public object listActivesubject(string group_search) { var groupID = NumUtil.ParseInteger(group_search); var group = _context.Subjects.Where(w => w.SubjectGroupID == groupID).Include(i => i.SubjectGroup).Where(w => w.Status == StatusType.Active); if (group != null) { return(group.Select(s => new { id = s.ID, name = s.Name, order = s.Order, status = s.Status.toStatusName(), group = s.SubjectGroup.Name, create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderBy(o => o.group).ThenBy(o2 => o2.order).ToArray()); } return(CreatedAtAction(nameof(listActivesubject), new { result = ResultCode.DataHasNotFound, message = ResultMessage.DataHasNotFound })); }
public void TestSyncUp(string pDeliveryID = "", string pDrumCode = "", string pDeliveryDetailID = "") { var currentdate = StoredProcedure.GetCurrentDate(); var cmsService = new MobileService(); CMS_Delivery _Delivery = new CMS_Delivery(); var cri = new MobileCri(); cri.Delivery_ID = NumUtil.ParseInteger(pDeliveryID); var result = cmsService.GetCMSDelivery(cri); if (result.Code == ReturnCode.SUCCESS) { var deliverys = result.Object as List <CMS_Delivery>; if (deliverys != null && deliverys.Count() == 1) { _Delivery = deliverys.FirstOrDefault(); _Delivery.Delivery_ID = _Delivery.Delivery_ID; _Delivery.Delivery_Order_No = _Delivery.Delivery_Order_No; _Delivery.Completed = true; _Delivery.Update_By = "Test"; _Delivery.Update_On = currentdate; List <CMS_Delivery_Detail> _Details = new List <CMS_Delivery_Detail>(); CMS_Delivery_Detail _Detail = new CMS_Delivery_Detail(); _Detail.CMS_Delivery_Detail_ID = NumUtil.ParseInteger(pDeliveryDetailID);; _Detail.Delivery_ID = _Delivery.Delivery_ID; _Detail.Drum_Code = pDrumCode; _Detail.Update_By = "Test"; _Detail.Update_On = currentdate; _Detail.Date_Delivered = currentdate; _Details.Add(_Detail); _Delivery.CMS_Delivery_Detail = _Details; } } var result2 = cmsService.UpdateCMSDelivery(_Delivery); }
public async Task <IActionResult> ModifyPrivilegeCode(PrivilegeCodeValidate model, IFormFile file) { if (!_loginServices.isInAdminRoles(this.GetRoles())) { return(RedirectToAction("Login", "Accounts")); } var pri = this._context.Privileges.Where(w => w.PrivilegeID == model.PrivilegeID).FirstOrDefault(); if (pri == null) { ModelState.AddModelError("Error", "ไม่พบข้อมูลสิทธิพิเศษ"); } if (ModelState.IsValid) { if (model.valid) { if (model.PrivilegeCodes != null && model.PrivilegeCodes.Count() > 0) { foreach (var item in model.PrivilegeCodes) { item.PrivilegeID = model.PrivilegeID; item.EffectiveDate = DateUtil.ToDate(item.effDate); item.ExpiryDate = DateUtil.ToDate(item.expDate); item.Status = item.Status; item.MaxUse = item.MaxUse; item.Create_On = DateUtil.Now(); this._context.PrivilegeCodes.Add(item); } this._context.SaveChanges(); return(RedirectToAction("PrivilegeCode", new { result = 1, PrivilegeID = model.PrivilegeID })); } } else { if (file == null) { ModelState.AddModelError("Error", "ไม่พบข้อมูลไฟล์นำเข้า"); } else { model.PrivilegeCodes = new List <PrivilegeCode>(); model.PrivilegeCodeFails = new List <PrivilegeCodeFail>(); ModelState.Clear(); using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream).ConfigureAwait(false); using (var package = new ExcelPackage(memoryStream)) { var workbook = package.Workbook; var worksheet = workbook.Worksheets.First(); var rowCount = worksheet.Dimension?.Rows; var colCount = worksheet.Dimension?.Columns; if (rowCount.HasValue && colCount.HasValue) { for (int row = 2; row <= rowCount.Value; row++) { try { var cformat = worksheet.Cells["C" + row].Style.Numberformat.Format; var eformat = worksheet.Cells["D" + row].Style.Numberformat.Format; worksheet.Cells["C" + row].Style.Numberformat.Format = "dd/MM/yyyy HH:mm"; worksheet.Cells["D" + row].Style.Numberformat.Format = "dd/MM/yyyy HH:mm"; var code = worksheet.Cells["A" + row].Value != null ? worksheet.Cells["A" + row].Value.ToString() : ""; var maxuse = worksheet.Cells["B" + row].Value != null ? worksheet.Cells["B" + row].Value.ToString() : ""; var eff = worksheet.Cells["C" + row].Value != null ? worksheet.Cells["C" + row].Value : null; var exp = worksheet.Cells["D" + row].Value != null ? worksheet.Cells["D" + row].Value : null; var status = worksheet.Cells["E" + row].Value != null ? worksheet.Cells["E" + row].Value.ToString() : ""; var msg = new StringBuilder(); if (string.IsNullOrEmpty(code)) { msg.AppendLine("ไม่พบข้อมูล Code"); } else { var pricode = this._context.PrivilegeCodes.Where(w => w.Code == code).FirstOrDefault(); if (pricode != null) { msg.AppendLine("Code ซ้ำในระบบ"); } } var pcode = new PrivilegeCode(); pcode.PrivilegeID = pri.PrivilegeID; pcode.Code = code; pcode.MaxUse = NumUtil.ParseInteger(maxuse); if (pcode.MaxUse == 0) { pcode.MaxUse = 1; } if (!string.IsNullOrEmpty(cformat) && cformat[0].ToString().ToLower() == "m") { pcode.EffectiveDate = (DateTime)eff; } else { pcode.EffectiveDate = DateUtil.ToDate(eff.ToString()); } if (!string.IsNullOrEmpty(eformat) && eformat[0].ToString().ToLower() == "m") { pcode.ExpiryDate = (DateTime)exp; } else { pcode.ExpiryDate = DateUtil.ToDate(exp.ToString()); } if (eff != null) { if (pcode.EffectiveDate == null) { pcode.EffectiveDate = DateTime.FromOADate((double)NumUtil.ParseDecimal(eff)); } } if (exp != null) { if (pcode.ExpiryDate == null) { pcode.ExpiryDate = DateTime.FromOADate((double)NumUtil.ParseDecimal(exp)); } } pcode.effDate = DateUtil.ToDisplayDate(pcode.EffectiveDate); pcode.expDate = DateUtil.ToDisplayDate(pcode.ExpiryDate); pcode.Status = StatusType.InActive; if (status == "Y") { pcode.Status = StatusType.Active; } if (string.IsNullOrEmpty(msg.ToString())) { model.PrivilegeCodes.Add(pcode); } else { model.PrivilegeCodes.Clear(); var fail = new PrivilegeCodeFail(); fail.Code = code; fail.EffectiveDate = pcode.effDate; fail.ExpiryDate = pcode.expDate; fail.MaxUse = pcode.MaxUse; fail.message = msg.ToString(); fail.Status = pcode.Status.toStatusName(); fail.row = row; model.PrivilegeCodeFails.Add(fail); } } catch (Exception ex) { ModelState.AddModelError("Error", ex.Message); } } } else { ModelState.AddModelError("Error", "รูปแบบไฟล์ไม่ถูกต้องหรือไม่มีข้อมูล"); } } } } } } return(View("PrivilegeCode", model)); }
public override string ToString() { StringBuilder builder = new StringBuilder(); using (StringWriter writer = new StringWriter(builder)) { using (HtmlTextWriter html = new HtmlTextWriter(writer)) { if (_controltype != AppControlType.Button && _controltype != AppControlType.ActionLink) { html.AddAttribute(HtmlTextWriterAttribute.Class, "row"); html.RenderBeginTag(HtmlTextWriterTag.Div); //Tag Row html.AddAttribute(HtmlTextWriterAttribute.Class, "col-md-" + _colSpan); html.RenderBeginTag(HtmlTextWriterTag.Div); //Tag Colspan html.AddAttribute(HtmlTextWriterAttribute.Class, "form-group"); html.RenderBeginTag(HtmlTextWriterTag.Div); //Tag Form Group if (_controltype == AppControlType.CheckBox) { html.AddAttribute(HtmlTextWriterAttribute.Class, "checkbox"); html.RenderBeginTag(HtmlTextWriterTag.Div); } if (_controltype == AppControlType.RadioButton) { html.AddAttribute(HtmlTextWriterAttribute.Class, "radio"); html.RenderBeginTag(HtmlTextWriterTag.Div); } if (_controltype == AppControlType.FileUpload) { html.AddAttribute(HtmlTextWriterAttribute.Class, "input-group"); html.RenderBeginTag(HtmlTextWriterTag.Div); //Tag Fileupload 1 html.AddAttribute(HtmlTextWriterAttribute.Class, "input-group-btn"); html.RenderBeginTag(HtmlTextWriterTag.Span); //Tag Fileupload 2 html.AddAttribute(HtmlTextWriterAttribute.Class, "btn btn-primary btn-file"); html.RenderBeginTag(HtmlTextWriterTag.Span); //Tag Fileupload 3 html.AddAttribute(HtmlTextWriterAttribute.Class, "fa fa-upload"); html.RenderBeginTag(HtmlTextWriterTag.I); //Tag Fileupload 4 html.RenderEndTag(); //End Tag Fileupload 4 } if (_controltype == AppControlType.GridData) { html.AddAttribute(HtmlTextWriterAttribute.Class, "table-responsive"); html.RenderBeginTag(HtmlTextWriterTag.Div);//Tag Grid Data } if (_controltype == AppControlType.TextDate) { if (!_readonly) { html.RenderBeginTag(HtmlTextWriterTag.Script); html.Write("$(function () { InitDatepickerByID('" + ID + "'); })"); html.RenderEndTag(); } } if (_controltype == AppControlType.TextTime) { if (!_readonly) { html.RenderBeginTag(HtmlTextWriterTag.Script); html.Write("$(function () { $('#" + ID + "').datetimepicker( {pickDate: false , format: 'HH:mm', pickSeconds: false, pick12HourFormat: false}) })"); html.RenderEndTag(); } } } if (_controltype != AppControlType.ValidateMessage) { this.Attributes.AddAttributes(html); html.RenderBeginTag(_tagname);//Tag Control this.RenderContents(html); } if (_controltype == AppControlType.ComboBox) { if (_options != null && _options.Count > 0) { var i = 0; foreach (var op in _options) { if (_selected != null) { if (op.Value == _selected.ToString()) { html.AddAttribute(HtmlTextWriterAttribute.Selected, "selected"); } } else { if (i == 0) { html.AddAttribute(HtmlTextWriterAttribute.Selected, "selected"); } } html.AddAttribute(HtmlTextWriterAttribute.Value, op.Value.Trim()); html.RenderBeginTag(HtmlTextWriterTag.Option); //Tag Option html.WriteEncodedText(op.Text.Trim()); html.RenderEndTag(); //End Option i++; } } } else if (_controltype == AppControlType.GridData) { if (_gridcolumnHeader != null) { html.RenderBeginTag(HtmlTextWriterTag.Thead); //Tag thead html.RenderBeginTag(HtmlTextWriterTag.Tr); //Tag Tr foreach (var col in _gridcolumnHeader) { if (col.Data_Type == GridDataType.none | col.Data_Type == GridDataType.usercontrol) { html.AddAttribute(HtmlTextWriterAttribute.Class, "no-sort"); if (!string.IsNullOrEmpty(col.Width)) { html.AddStyleAttribute(HtmlTextWriterStyle.Width, col.Width); } else { html.AddStyleAttribute(HtmlTextWriterStyle.Width, "150px"); } html.RenderBeginTag(HtmlTextWriterTag.Th);//Tag Th } else if (col.Data_Type == GridDataType.index) { html.AddAttribute(HtmlTextWriterAttribute.Class, "sort-numeric"); if (!string.IsNullOrEmpty(col.Width)) { html.AddStyleAttribute(HtmlTextWriterStyle.Width, col.Width); } else { html.AddStyleAttribute(HtmlTextWriterStyle.Width, "70px"); } html.RenderBeginTag(HtmlTextWriterTag.Th);//Tag Th } else { html.AddAttribute(HtmlTextWriterAttribute.Class, "sort-" + col.Data_Type.ToString()); if (!string.IsNullOrEmpty(col.Width)) { html.AddStyleAttribute(HtmlTextWriterStyle.Width, col.Width); } html.RenderBeginTag(HtmlTextWriterTag.Th);//Tag Th } html.WriteEncodedText(col.Column_Name.Replace("_", " ")); html.RenderEndTag(); //End Option } html.RenderEndTag(); //End Tag Tr html.RenderEndTag(); //End Tag thead html.RenderBeginTag(HtmlTextWriterTag.Tbody); //Tag Th;//Tag tbody if (_gridrows != null) { foreach (var row in _gridrows) { html.RenderBeginTag(HtmlTextWriterTag.Tr);//Tag Tr for (var i = 0; i < row.Item.Count; i++) { var item = row.Item[i]; if (_gridcolumnHeader[i].Data_Type == GridDataType.amount) { html.AddAttribute(HtmlTextWriterAttribute.Class, "text-right"); html.RenderBeginTag(HtmlTextWriterTag.Td);//Tag Td if (item.Value != null) { var amount = NumUtil.ParseDecimal(item.Value.ToString()); html.WriteEncodedText(NumUtil.FormatCurrency(amount)); } else { html.WriteEncodedText("0"); } html.RenderEndTag();//End Tag Td } else if (_gridcolumnHeader[i].Data_Type == GridDataType.index) { html.AddAttribute(HtmlTextWriterAttribute.Class, "text-center"); html.RenderBeginTag(HtmlTextWriterTag.Td);//Tag Td if (item.Value != null) { var amount = NumUtil.ParseInteger(item.Value.ToString()); html.WriteEncodedText(amount.ToString("n0")); } html.RenderEndTag();//End Tag Td } else if (_gridcolumnHeader[i].Data_Type == GridDataType.numeric) { html.AddAttribute(HtmlTextWriterAttribute.Class, "text-right"); html.RenderBeginTag(HtmlTextWriterTag.Td);//Tag Td if (item.Value != null) { var amount = NumUtil.ParseInteger(item.Value.ToString()); html.WriteEncodedText(amount.ToString("n0")); } html.RenderEndTag();//End Tag Td } else if (_gridcolumnHeader[i].Data_Type == GridDataType.usercontrol) { html.RenderBeginTag(HtmlTextWriterTag.Td);//Tag Td if (item.Value != null) { html.Write(item.Value.ToString()); } html.RenderEndTag();//End Tag Td } else { html.RenderBeginTag(HtmlTextWriterTag.Td);//Tag Td if (item.Value != null) { html.WriteEncodedText(item.Value.ToString()); } html.RenderEndTag();//End Tag Td } } html.RenderEndTag();//End Tag Tr } } html.RenderEndTag();//End Tag tbody } } if (_controltype == AppControlType.Button || _controltype == AppControlType.ActionLink || _controltype == AppControlType.Label) { if (!string.IsNullOrEmpty(_icon)) { html.AddAttribute(HtmlTextWriterAttribute.Class, _icon); html.RenderBeginTag(HtmlTextWriterTag.I); //Tag i html.RenderEndTag(); //End Tag i } if (Text != null) { html.WriteEncodedText(Text); } } if (_controltype == AppControlType.TextArea) { if (Value != null) { html.WriteEncodedText(Value.ToString()); } } if (_controltype != AppControlType.ValidateMessage) { html.RenderEndTag();//End Tag Control } if (_controltype == AppControlType.RadioButton | _controltype == AppControlType.CheckBox) { html.AddAttribute(HtmlTextWriterAttribute.For, ID); html.RenderBeginTag(HtmlTextWriterTag.Label); //Tag Radio or Check box label html.WriteEncodedText(Text); html.RenderEndTag(); //End Tag Radio or Check box label } if (this.HtmlValidateString != null) { html.AddAttribute(HtmlTextWriterAttribute.Class, "validation-error"); html.RenderBeginTag(HtmlTextWriterTag.Div); //Tag validation-error html.Write(_htmlvalidateString.ToHtmlString()); html.RenderEndTag(); //End Tag validation-error } if (_controltype != AppControlType.Button && _controltype != AppControlType.ActionLink) { if (_controltype == AppControlType.GridData) { html.RenderEndTag(); //Tag Grid data html.RenderBeginTag(HtmlTextWriterTag.Script); //Tag script var addbutton = "null"; if (_gridAddButton != null) { addbutton = _gridAddButton.ToString(); } if (!string.IsNullOrEmpty(addbutton) && addbutton != "null") { html.Write("$(function () { InitDatatable('" + ID + "', '" + addbutton + "', null); })"); } else { html.Write("$(function () { InitDatatable('" + ID + "', null, null); })"); } html.RenderEndTag(); //End script; } if (_controltype == AppControlType.FileUpload) { html.RenderEndTag(); //Tag Fileupload 1 html.RenderEndTag(); //Tag Fileupload 2 html.RenderBeginTag("input class='form-control' type='text' readonly=''"); //Tag Fileupload Text html.RenderEndTag(); //End Tag Fileupload Text html.RenderEndTag(); //Tag Fileupload 3 } if (_controltype == AppControlType.RadioButton) { html.RenderEndTag();//End Tag Radio } if (_controltype == AppControlType.CheckBox) { html.RenderEndTag(); //End Tag Check box } html.RenderEndTag(); //End Tag Form Group html.RenderEndTag(); //End Tag Colspan html.RenderEndTag(); //End Row } } } var str = builder.ToString(); if (_controltype == AppControlType.ComboBox) { Regex RegexBetweenTags = new Regex(@">(?! )\s+", RegexOptions.Compiled); Regex RegexLineBreaks = new Regex(@"([\n\s])+?(?<= {2,})<", RegexOptions.Compiled); str = RegexBetweenTags.Replace(str, ">"); str = RegexLineBreaks.Replace(str, "<"); str = Regex.Replace(str, @"\t|\n|\r", ""); str = str.Trim(); } return(str); }
public async Task <JsonResult> ValidateCode(int?PrivilegeID, IFormFile excelfile) { if (!_loginServices.isInAdminRoles(this.GetRoles())) { return(Json(new { responseCode = "-403", responseDesc = "คุณไม่มีสิทธิ์เข้าถึงระบบ", })); } if (excelfile == null) { return(Json(new { responseCode = "-1", responseDesc = "ไม่พบข้อมูลไฟล์นำเข้า", })); } if (!PrivilegeID.HasValue || PrivilegeID == 0) { return(Json(new { responseCode = "-1", responseDesc = "ไม่พบข้อมูลสิทธิพิเศษ", })); } var pID = PrivilegeID; var pri = this._context.Privileges.Where(w => w.PrivilegeID == PrivilegeID).FirstOrDefault(); if (pri == null) { return(Json(new { responseCode = "-1", responseDesc = "ไม่พบข้อมูลสิทธิพิเศษ", })); } var codelist = new List <PrivilegeCode>(); using (var memoryStream = new MemoryStream()) { await excelfile.CopyToAsync(memoryStream).ConfigureAwait(false); using (var package = new ExcelPackage(memoryStream)) { var workbook = package.Workbook; var worksheet = workbook.Worksheets.First(); var rowCount = worksheet.Dimension?.Rows; var colCount = worksheet.Dimension?.Columns; if (rowCount.HasValue && colCount.HasValue) { for (int row = 2; row <= rowCount.Value; row++) { try { var cformat = worksheet.Cells["C" + row].Style.Numberformat.Format; var eformat = worksheet.Cells["D" + row].Style.Numberformat.Format; worksheet.Cells["C" + row].Style.Numberformat.Format = "dd/MM/yyyy HH:mm"; worksheet.Cells["D" + row].Style.Numberformat.Format = "dd/MM/yyyy HH:mm"; var code = worksheet.Cells["A" + row].Value != null ? worksheet.Cells["A" + row].Value.ToString() : ""; var maxuse = worksheet.Cells["B" + row].Value != null ? worksheet.Cells["B" + row].Value.ToString() : ""; var eff = worksheet.Cells["C" + row].Value != null ? worksheet.Cells["C" + row].Value : null; var exp = worksheet.Cells["D" + row].Value != null ? worksheet.Cells["D" + row].Value : null; var status = worksheet.Cells["E" + row].Value != null ? worksheet.Cells["E" + row].Value.ToString() : ""; var pcode = new PrivilegeCode(); pcode.PrivilegeID = pri.PrivilegeID; pcode.Code = code; pcode.MaxUse = NumUtil.ParseInteger(maxuse); if (pcode.MaxUse == 0) { pcode.MaxUse = null; } if (!string.IsNullOrEmpty(cformat) && cformat[0].ToString().ToLower() == "m") { pcode.EffectiveDate = (DateTime)eff; } else { pcode.EffectiveDate = DateUtil.ToDate(eff.ToString()); } if (!string.IsNullOrEmpty(eformat) && eformat[0].ToString().ToLower() == "m") { pcode.ExpiryDate = (DateTime)exp; } else { pcode.ExpiryDate = DateUtil.ToDate(exp.ToString()); } if (eff != null) { if (pcode.EffectiveDate == null) { pcode.EffectiveDate = DateTime.FromOADate((double)NumUtil.ParseDecimal(eff)); } } if (exp != null) { if (pcode.ExpiryDate == null) { pcode.ExpiryDate = DateTime.FromOADate((double)NumUtil.ParseDecimal(exp)); } } pcode.effDate = DateUtil.ToDisplayDate(pcode.EffectiveDate); pcode.expDate = DateUtil.ToDisplayDate(pcode.ExpiryDate); pcode.Status = StatusType.InActive; if (status == "Y") { pcode.Status = StatusType.Active; } codelist.Add(pcode); } catch (Exception ex) { } } } } } return(Json(new { responseCode = "1", responseDesc = "SUCCESS", data = codelist, })); }
public object upload([FromBody] JsonElement json) { var model = JsonConvert.DeserializeObject <ImportExamRegisterDTO>(json.GetRawText()); if (model != null && model.fileupload != null) { var file = Convert.FromBase64String(model.fileupload.value); using (MemoryStream ms = new MemoryStream(file)) { using (ExcelPackage package = new ExcelPackage(ms)) { if (package.Workbook.Worksheets.Count == 0) { return(CreatedAtAction(nameof(upload), new { result = ResultCode.InputHasNotFound, message = ResultMessage.InputHasNotFound })); } else { var worksheet = package.Workbook.Worksheets.First(); int totalRows = worksheet.Dimension.End.Row; for (int i = 2; i <= totalRows; i++) { var txt = worksheet.Cells[i, 1].Text.ToString(); if (!string.IsNullOrEmpty(txt)) { var student = _context.Students.Where(w => w.StudentCode == txt).FirstOrDefault(); if (student != null) { var examidint = NumUtil.ParseInteger(model.examid); var reged = _context.ExamRegisters.Where(w => w.StudentID == student.ID & w.ExamID == examidint).FirstOrDefault(); if (reged == null) { var register = new ExamRegister(); register.StudentID = student.ID; register.ExamID = examidint; register.ExamRegisterType = ExamRegisterType.Advance; register.Create_On = DateUtil.Now(); register.Update_On = DateUtil.Now(); register.Create_By = model.update_by; register.Update_By = model.update_by; _context.ExamRegisters.Add(register); } } } } _context.SaveChanges(); var examid = NumUtil.ParseInteger(model.examid); var exam = _context.Exams.Where(w => w.ID == examid).FirstOrDefault(); if (exam != null) { exam.Update_On = DateUtil.Now(); exam.Update_By = model.update_by; exam.RegisterCnt = _context.ExamRegisters.Where(w => w.ExamID == examid).Count(); _context.SaveChanges(); return(CreatedAtAction(nameof(upload), new { result = ResultCode.Success, message = ResultMessage.Success, registercnt = exam.RegisterCnt })); } } } } } return(CreatedAtAction(nameof(upload), new { result = ResultCode.InvalidInput, message = ResultMessage.InvalidInput })); }
public IActionResult Index(ReportDTO model) { var user = this._context.Users.Include(i => i.UserRole).Where(w => w.UserName == this.HttpContext.User.Identity.Name).FirstOrDefault(); if (user == null) { return(RedirectToAction("Login", "Accounts")); } if (user.UserRole.RoleName != RoleName.Merchant) { return(RedirectToAction("Login", "Accounts")); } int pageno = 1; if (this.RouteData.Values["pno"] != null) { pageno = NumUtil.ParseInteger(this.RouteData.Values["pno"].ToString()); if (pageno == 0) { pageno = 1; } } int skipRows = (pageno - 1) * 100; model.Redeems = this._context.Redeems .Include(i => i.Customer) .Include(i => i.Customer.User) .Include(i => i.Customer.CustomerClass) .Include(i => i.Privilege) .Include(i => i.Privilege.Merchant) .Where(w => w.Privilege.Merchant.UserID == user.ID); if (model.customerClassID.HasValue) { model.Redeems = model.Redeems.Where(c => c.Customer.CustomerClassID == model.customerClassID); } if (!string.IsNullOrEmpty(model.search_text)) { var text = model.search_text.ToLower().Trim(); model.Redeems = model.Redeems .Where(c => (!string.IsNullOrEmpty(c.Customer.NameTh) && c.Customer.NameTh.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.SurNameTh) && c.Customer.SurNameTh.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.Email) && c.Customer.Email.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.User.UserName) && c.Customer.User.UserName.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.MoblieNo) && c.Customer.MoblieNo.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.IDCard) && c.Customer.IDCard.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.NameEn) && c.Customer.NameEn.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.SurNameEn) && c.Customer.SurNameEn.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.RefCode) && c.Customer.RefCode.ToLower().Contains(text)) | (!string.IsNullOrEmpty(c.Customer.FriendCode) && c.Customer.FriendCode.ToLower().Contains(text)) ); } if (model.search_privilege.HasValue) { model.Redeems = model.Redeems.Where(c => c.PrivilegeID == model.search_privilege); } if (!string.IsNullOrEmpty(model.search_sdate)) { var sdate = DateUtil.ToDate(model.search_sdate); model.Redeems = model.Redeems.Where(c => c.RedeemDate.Value.Date >= sdate.Value.Date); } if (!string.IsNullOrEmpty(model.search_edate)) { var edate = DateUtil.ToDate(model.search_edate); model.Redeems = model.Redeems.Where(c => c.RedeemDate.Value.Date <= edate.Value.Date); } model.Redeems = model.Redeems.OrderByDescending(c => c.RedeemDate); ViewBag.ItemCount = model.Redeems.Count(); ViewBag.PageLength = (ViewBag.ItemCount / 100); if (ViewBag.ItemCount % 100 > 0) { ViewBag.PageLength += 1; } ViewBag.PageNo = pageno; model.Redeems = model.Redeems.Skip(skipRows).Take(100); var privileges = this._context.Privileges .Include(s => s.Merchant) .Include(s => s.PrivilegeImages) .Include(s => s.MerchantCategory) .Where(w => w.Status == StatusType.Active & (!w.StartDate.HasValue || w.StartDate.Value.Date <= DateUtil.Now().Date) & (!w.EndDate.HasValue || w.EndDate.Value.Date >= DateUtil.Now().Date)); ViewBag.ListCustomerClass = this._context.CustomerClasses; var merchant = _context.Merchants.Where(w => w.UserID == user.ID).FirstOrDefault(); if (merchant != null) { ViewBag.MerchantName = merchant.MerchantName; } return(View("Index", model)); }
public ActionResult GlobalLookup(GlobalLookupViewModel model) { var gService = new GlobalLookupService(); if (ModelState.IsValid) { var gdata = new Global_Lookup_Data(); if (model.operation == Operation.U || model.operation == Operation.D) { var cri = new GlobalLookupCriteria(); cri.Lookup_Data_ID = model.Lookup_Data_ID; var result = gService.GetGlobalLookupData(cri); if (result.Code == ReturnCode.SUCCESS) { var gdatas = result.Object as List <Global_Lookup_Data>; if (gdatas != null && gdatas.Count() == 1) { gdata = gdatas.FirstOrDefault(); } } } if (model.operation != Operation.D) { gdata.Def_ID = model.Def_ID.Value; gdata.Data_Code = model.Data_Code; gdata.Name = model.Name; } if (model.operation == Operation.C) { gdata.Record_Status = Record_Status.Active; model.result = gService.InsertGlobalLookupData(gdata); } else if (model.operation == Operation.U) { model.result = gService.UpdateGlobalLookupData(gdata); } else if (model.operation == Operation.D) { gdata.Record_Status = Record_Status.Delete; model.result = gService.UpdateGlobalLookupData(gdata); if (model.result.Code == ReturnCode.SUCCESS) { model.result = new ServiceResult() { Code = ReturnCode.SUCCESS, Msg = Success.GetMessage(ReturnCode.SUCCESS_DELETE), Field = Resource.Global_Lookup } } ; else { model.result = new ServiceResult() { Code = ReturnCode.ERROR_DELETE, Msg = Error.GetMessage(ReturnCode.ERROR_DELETE), Field = Resource.Global_Lookup } }; var route = new RouteValueDictionary(model.result); route.Add("search_Def_ID", gdata.Def_ID); return(RedirectToAction("GlobalLookup", route)); } if (model.result.Code == ReturnCode.SUCCESS) { var route = new RouteValueDictionary(model.result); route.Add("search_Def_ID", model.Def_ID); return(RedirectToAction("GlobalLookup", route)); } } var cService = new ComboService(); model.cGlobalDefList = cService.LstLookupDef(); if (model.cGlobalDefList.Count > 0 && !model.search_Def_ID.HasValue) { model.search_Def_ID = NumUtil.ParseInteger(model.cGlobalDefList[0].Value); } if (model.search_Def_ID.HasValue) { var cri = new GlobalLookupCriteria(); var result = gService.GetGlobalLookupData(cri); if (result.Code == ReturnCode.SUCCESS) { model.GlobalDataList = result.Object as List <Global_Lookup_Data>; } } return(View(model)); } }
public object listAllstaff(string text_search, string status_search, string role_search) { var staff = _context.Staffs.Include(i => i.User).Where(w => 1 == 1); if (!string.IsNullOrEmpty(status_search)) { staff = staff.Where(w => w.Status == status_search.toStatus()); } if (!string.IsNullOrEmpty(role_search)) { var role = NumUtil.ParseInteger(role_search); if (role == 0) { staff = staff.Where(w => w.isAdmin == true); } else if (role == 1) { staff = staff.Where(w => w.isMasterAdmin == true); } else if (role == 2) { staff = staff.Where(w => w.isQuestionAppr == true); } else if (role == 3) { staff = staff.Where(w => w.isMasterQuestionAppr == true); } else if (role == 4) { staff = staff.Where(w => w.isTestAppr == true); } else if (role == 5) { staff = staff.Where(w => w.isMasterTestAppr == true); } } var staffs = new List <Staff>(); if (!string.IsNullOrEmpty(text_search)) { var text_splits = text_search.Split(",", StringSplitOptions.RemoveEmptyEntries); foreach (var text_split in text_splits) { if (!string.IsNullOrEmpty(text_split)) { var text = text_split.Trim(); staffs.AddRange(staff.Where(w => w.FirstName.Contains(text) | w.LastName.Contains(text) | w.IDCard.Contains(text) | w.Phone.Contains(text) | w.Phone2.Contains(text) | w.Email.Contains(text) | w.Passport.Contains(text) | w.StaffCode.Contains(text) | (w.FirstName + " " + w.LastName).Contains(text) )); } } staffs = staffs.Distinct().ToList(); } else { staffs = staff.ToList(); } return(staffs.Select(s => new { id = s.ID, prefix = s.Prefix.toPrefixName(), firstname = s.FirstName, lastname = s.LastName, idcard = s.IDCard, phone = s.Phone, phone2 = s.Phone2, email = s.Email, address = s.Address, passport = s.Passport, staffcode = s.StaffCode, userid = s.UserID, username = s.User.UserName, opendate = DateUtil.ToDisplayDate(s.OpenDate), expirydate = DateUtil.ToDisplayDate(s.ExpiryDate), status = s.Status.toStatusName(), isadmin = s.isAdmin, ismasteradmin = s.isMasterAdmin, isquestionappr = s.isQuestionAppr, ismasterquestionappr = s.isMasterQuestionAppr, istestappr = s.isTestAppr, ismastertestappr = s.isMasterTestAppr, create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderBy(o => o.firstname).ThenBy(o2 => o2.lastname).ToArray()); }
public object listAlltest(string text_search, string status_search, string group_search, string subject_search, int pageno = 1) { var test = _context.Tests.Include(i => i.Subject).Include(i => i.Subject.SubjectGroup).Where(w => 1 == 1); if (!string.IsNullOrEmpty(status_search)) { test = test.Where(w => w.Status == status_search.toStatus()); } if (!string.IsNullOrEmpty(subject_search)) { var subjectID = NumUtil.ParseInteger(subject_search); if (subjectID > 0) { test = test.Where(w => w.SubjectID == subjectID); } } if (!string.IsNullOrEmpty(group_search)) { var groupID = NumUtil.ParseInteger(group_search); if (groupID > 0) { test = test.Where(w => w.Subject.SubjectGroupID == groupID); } } var tests = new List <Test>(); if (!string.IsNullOrEmpty(text_search)) { var text_splits = text_search.Split(",", StringSplitOptions.RemoveEmptyEntries); foreach (var text_split in text_splits) { if (!string.IsNullOrEmpty(text_split)) { var text = text_split.Trim(); tests.AddRange(test.Where(w => w.Name.Contains(text))); } } tests = tests.Distinct().ToList(); } else { tests = test.ToList(); } int skipRows = (pageno - 1) * 25; var itemcnt = tests.Count(); var pagelen = itemcnt / 25; if (itemcnt % 25 > 0) { pagelen += 1; } return(CreatedAtAction(nameof(listAlltest), new { data = tests.Select(s => new { id = s.ID, name = s.Name, status = s.Status.toStatusName(), group = s.Subject.SubjectGroup.Name, subject = s.Subject.Name, subjectindex = s.Subject.Order, testcode = s.TestCode, approvalstatus = s.ApprovalStatus, approvalstatusname = s.ApprovalStatus.toTestApprovalStatusName(), create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderByDescending(o => o.id).Skip(skipRows).Take(25).ToArray(), pagelen = pagelen, itemcnt = itemcnt, }));; }
public object listAllexam(string text_search, string status_search, string group_search, string subject_search, string from_search, string to_search, int?move_from, int pageno = 1) { /*repair test student exam*/ var curdate = DateUtil.Now().Date; var rtstudents = _context.TestResultStudents.Include(i => i.Test).Where(w => w.ExamingStatus == ExamingStatus.Examing); foreach (var rtstudent in rtstudents) { if (rtstudent.Test != null) { var remain = FuncUtil.GetTimeRemaining(rtstudent.Test.TimeLimitType, rtstudent.Test.TimeLimit, rtstudent.Start_On); if (remain <= 0) { rtstudent.ExamingStatus = ExamingStatus.Done; rtstudent.Other = true; rtstudent.Update_On = curdate; rtstudent.End_On = rtstudent.Start_On.Value.AddSeconds(FuncUtil.GetMaxTimeLimit(rtstudent.Test.TimeLimitType, rtstudent.Test.TimeLimit)); } } } _context.SaveChanges(); var exam = _context.Exams.Include(i => i.Test).Include(i => i.Subject).Include(i => i.Subject.SubjectGroup).Where(w => 1 == 1); if (move_from.HasValue) { exam = exam.Where(w => w.ID != move_from & w.ExamDate.Value >= curdate.Date); } if (!string.IsNullOrEmpty(status_search)) { exam = exam.Where(w => w.Status == status_search.toStatus()); } if (!string.IsNullOrEmpty(subject_search)) { var subjectID = NumUtil.ParseInteger(subject_search); if (subjectID > 0) { exam = exam.Where(w => w.SubjectID == subjectID); } } if (!string.IsNullOrEmpty(group_search)) { var groupID = NumUtil.ParseInteger(group_search); if (groupID > 0) { exam = exam.Where(w => w.Subject.SubjectGroupID == groupID); } } if (!string.IsNullOrEmpty(from_search)) { var date = DateUtil.ToDate(from_search); exam = exam.Where(w => w.ExamDate.Value.Date >= date); } if (!string.IsNullOrEmpty(to_search)) { var date = DateUtil.ToDate(to_search); exam = exam.Where(w => w.ExamDate.Value.Date <= date); } var exams = new List <Exam>(); if (!string.IsNullOrEmpty(text_search)) { var text_splits = text_search.Split(",", StringSplitOptions.RemoveEmptyEntries); foreach (var text_split in text_splits) { if (!string.IsNullOrEmpty(text_split)) { var text = text_split.Trim(); var registerIDs = _context.ExamRegisters.Where(w => w.Student.FirstName.Contains(text) | w.Student.LastName.Contains(text) | w.Student.FirstNameEn.Contains(text) | w.Student.LastNameEn.Contains(text) | w.Student.IDCard.Contains(text) | w.Student.Phone.Contains(text) | w.Student.Email.Contains(text) | w.Student.Passport.Contains(text) | w.Student.StudentCode.Contains(text) | (w.Student.FirstName + " " + w.Student.LastName).Contains(text) | (w.Student.FirstNameEn + " " + w.Student.LastNameEn).Contains(text) ).Select(s => s.ExamID); exams.AddRange(exam.Where(w => w.Test.Name.Contains(text) | w.ExamCode.Contains(text) | registerIDs.Contains(w.ID) )); } } exams = exams.Distinct().ToList(); } else { exams = exam.ToList(); } int skipRows = (pageno - 1) * 25; var itemcnt = exams.Count(); var pagelen = itemcnt / 25; if (itemcnt % 25 > 0) { pagelen += 1; } return(CreatedAtAction(nameof(listAllexam), new { data = exams.Select(s => new { id = s.ID, test = s.ExamTestType == ExamTestType.Random ? _context.Tests.Where(w => w.SubjectID == s.SubjectID & w.Status == StatusType.Active).Count() == 1 ? _context.Tests.Where(w => w.SubjectID == s.SubjectID & w.Status == StatusType.Active).FirstOrDefault().Name : "สุ่ม" : s.Test.Name, status = s.Status.toStatusName(), group = s.Subject.SubjectGroup.Name, subject = s.Subject.Name, subjectorder = s.Subject.Order, examcode = s.ExamCode, examdate = DateUtil.ToDisplayDate(s.ExamDate), date = s.ExamDate, examperiod = s.ExamPeriod.toExamPeriodName(), examperiodid = s.ExamPeriod, examtesttype = s.ExamTestType.toExamTestType(), registercnt = s.RegisterCnt, examregistercnt = s.ExamRegisterCnt, create_on = DateUtil.ToDisplayDateTime(s.Create_On), create_by = s.Create_By, update_on = DateUtil.ToDisplayDateTime(s.Update_On), update_by = s.Update_By, }).OrderByDescending(o => o.date).ThenBy(o => o.examperiodid).ThenBy(o => o.group).ThenBy(o => o.subjectorder).Skip(skipRows).Take(25).ToArray(), pagelen = pagelen, itemcnt = itemcnt, }));; }