public List <sp_calendar_dashboard_Result> searchCalendar_v2(dashBoardModel value) { try { using (StandardCanEntities context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "dashBoard", update_date = DateTime.Now }); context.SaveChanges(); List <sp_calendar_dashboard_Result> result = context.sp_calendar_dashboard(userId).ToList(); return(result); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public IEnumerable <sp_trainning_search_Result> searchTraining(projectTrainingScheduleModel value) { try { //if (String.IsNullOrEmpty(value.user_id)) //{ // throw new Exception("Unauthorized Access"); //} //var userId = JwtHelper.GetUserIdFromToken(value.user_id); //if (String.IsNullOrEmpty(userId)) //{ // throw new Exception("Unauthorized Access"); //} StandardCanEntities context = new StandardCanEntities(); JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "searchTraining", update_date = DateTime.Now }); context.SaveChanges(); IEnumerable <sp_trainning_search_Result> result = context.sp_trainning_search(value.project_year, value.project_id, value.date_form, value.date_to, value.training_name, "", value.status_id).AsEnumerable(); return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }
public IEnumerable <sp_emp_temporary_search_v2_Result> search_Temporary(empCheckInModel value) { try { JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); StandardCanEntities context = new StandardCanEntities(); if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } context.interface_log.Add(new interface_log { ID = 1, data_log = json, module = "search_Temporary", update_date = DateTime.Now }); context.SaveChanges(); IEnumerable <sp_emp_temporary_search_v2_Result> result = context.sp_emp_temporary_search_v2(userId, value.start_date, value.stop_date, value.emp_code_from, value.emp_code_to, value.depart_from, value.depart_to, value.fname, value.lname).AsEnumerable(); return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }
public projectTrainingMasterModel master(projectTrainingScheduleModel value) { projectTrainingMasterModel result = new projectTrainingMasterModel(); try { using (var context = new StandardCanEntities()) { //if (String.IsNullOrEmpty(value.user_id)) //{ // throw new Exception("Unauthorized Access"); //} //var userId = JwtHelper.GetUserIdFromToken(value.user_id); //if (String.IsNullOrEmpty(userId)) //{ // throw new Exception("Unauthorized Access"); //} JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "Training_master", update_date = DateTime.Now }); context.SaveChanges(); string sql = "select convert(nvarchar(4), MPJ_YEAR) code, convert(nvarchar(4), MPJ_YEAR) [text] "; sql += " from MAS_PROJECT "; sql += " where MPJ_YEAR is not null "; sql += " group by MPJ_YEAR "; result.project_year = context.Database.SqlQuery <dropdown>(sql).ToList(); sql = "select convert(nvarchar(5), MPJ_ID) code "; sql += " , MPJ_NAME [text] "; sql += " from MAS_PROJECT "; sql += " where MPJ_STATUS = 1 "; sql += " order by MPJ_NAME "; result.project_name = context.Database.SqlQuery <dropdown>(sql).ToList(); var expenseData = context.MAS_EXPENSE.ToList(); foreach (var item in expenseData) { projectTrainingExpenseModel expenseModel = new projectTrainingExpenseModel(); expenseModel.id = item.MEXP_ID.ToString(); expenseModel.expense_name = item.MEXP_NAME; result.project_expense.Add(expenseModel); } result.depart = context.sp_depart_search().ToList(); } } catch (Exception ex) { throw new Exception(ex.Message); } return(result); }
public benefitsDataResultModel search(benefitsModel value) { benefitsDataResultModel result = new benefitsDataResultModel(); result.message = new messageModel(); try { using (StandardCanEntities context = new StandardCanEntities()) { var _Gapi = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH"); var _Gpath = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH"); JsonPathModel jsonPath = new JsonPathModel(); if (_Gpath != null) { jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel)); } if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "Benefits_search", update_date = DateTime.Now }); context.SaveChanges(); var data = context.MAS_BENEFITS.Where(a => a.mb_title.Contains(value.title)).ToList(); result.benefitData = new List <benefitsModel>(); foreach (var item in data) { benefitsModel news = new benefitsModel(); news.id = item.MB_ID.ToString(); news.title = item.mb_title; news.detail = item.mb_detail; news.url = !String.IsNullOrEmpty(item.mb_link_url) ? _Gapi.GGC_VAL + jsonPath.benefits + item.mb_link_url : null; result.benefitData.Add(news); } result.message.status = "S"; result.message.message = "Success"; } } catch (Exception ex) { result.message.status = "E"; result.message.message = ex.Message.ToString(); } return(result); }
public dashBoardModel search(dashBoardModel value) { dashBoardModel result = new dashBoardModel(); result.message = new messageModel(); try { using (StandardCanEntities context = new StandardCanEntities()) { var _Gapi = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH"); var _Gpath = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH"); JsonPathModel jsonPath = new JsonPathModel(); if (_Gpath != null) { jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel)); } if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "dashBoard", update_date = DateTime.Now }); context.SaveChanges(); var data = context.IMAGE_SLIDE.Where(a => a.is_status == 1).ToList().OrderBy(a => a.is_order_by).ToList(); result.imgList = new List <dashBoardImg>(); foreach (var item in data) { dashBoardImg news = new dashBoardImg(); string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.imageSlide), Path.GetFileName(item.is_url_image)); byte[] bytes = File.ReadAllBytes(path); news.base64 = Convert.ToBase64String(bytes); result.imgList.Add(news); } result.message.status = "S"; result.message.message = "Success"; } } catch (Exception ex) { result.message.status = "E"; result.message.message = ex.Message.ToString(); } return(result); }
public messageModel save_Regular(empCheckInModel value) { messageModel result = new messageModel(); try { JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); using (var context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } context.interface_log.Add(new interface_log { ID = 1, data_log = json, module = "save_Regular", update_date = DateTime.Now }); context.SaveChanges(); int ret = context.sp_emp_regular_delete(userId); if (value.data != null) { foreach (var item in value.data) { context.sp_emp_regular_insert(userId, item.emp_code); } } } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public projectFomularResult searchFomulay(projectTrainingScheduleModel value) { projectFomularResult result = new projectFomularResult(); result.message = new messageModel(); try { using (StandardCanEntities context = new StandardCanEntities()) { //if (String.IsNullOrEmpty(value.user_id)) //{ // throw new Exception("Unauthorized Access"); //} //var userId = JwtHelper.GetUserIdFromToken(value.user_id); //if (String.IsNullOrEmpty(userId)) //{ // throw new Exception("Unauthorized Access"); //} JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "searchFomulay", update_date = DateTime.Now }); context.SaveChanges(); string sql = ""; sql += "select convert(int, b.MFV_ORDER_BY) order_by, MFV_VALUE value, MFV_TEXT text "; sql += " from MAS_COURSE a inner "; sql += " join MAS_FORMULA_VALUE b on a.MFL_ID = b.MFL_ID "; sql += " where a.MCS_ID = " + value.course_id + " and MFV_STATUS = 1 "; sql += " order by b.MFV_ORDER_BY "; result.data = context.Database.SqlQuery <fomularField>(sql).ToList(); result.message.status = "S"; result.message.message = "Success"; } } catch (Exception ex) { result.message.status = "E"; result.message.message = ex.Message.ToString(); } return(result); }
public messageModel tab_note_update(employeeModel value) { messageModel result = new messageModel(); try { JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); using (var context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } context.interface_log.Add(new interface_log { module = "tab_behavior_update", data_log = json, update_date = DateTime.Now }); context.SaveChanges(); context.sp_emp_profile_tabnote_update(value.emp_code, value.note); } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public IEnumerable <dashBoardCalendarViewModel> searchCalendarStore(dashBoardModel value) { List <dashBoardCalendarViewModel> result = new List <dashBoardCalendarViewModel>(); try { using (StandardCanEntities context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "dashBoard", update_date = DateTime.Now }); context.SaveChanges(); var resultStore = ""; } } catch (Exception ex) { throw new Exception(ex.Message); } return(result); }
public List <dashBoardCalendarViewModel> searchCalendar(dashBoardModel value) { List <dashBoardCalendarViewModel> result = new List <dashBoardCalendarViewModel>(); try { using (StandardCanEntities context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "dashBoard", update_date = DateTime.Now }); context.SaveChanges(); var queryRoom = (from a in context.BOOK_ROOM join b in context.MAS_ROOM on a.MRM_ID equals b.MRM_ID join c in context.MAS_APPROVE_STATUS on a.br_status equals c.MAS_ID join d in context.EMP_PROFILE on a.br_create_by equals d.EMP_ID where a.br_create_by.ToString() == userId && c.mas_name == "Approved" select new { Type = "1", Title = b.MRM_CODE, Start = a.br_date + " " + a.br_start_time, End = a.br_date + " " + a.br_stop_time, Id = a.BR_ID, Color = b.MRM_COLOR, StsText = c.mas_name, Create_by = a.br_create_by }).ToList(); foreach (var item in queryRoom) { dashBoardCalendarViewModel viewModel = new dashBoardCalendarViewModel(); viewModel.id = item.Id.ToString(); viewModel.type = item.Type; viewModel.title = item.Title; viewModel.start = item.Start; viewModel.end = item.End; viewModel.color = item.Color; //if(item.Create_by.ToString() == userId) //{ // result.Add(viewModel); //} result.Add(viewModel); } var queryCar = (from a in context.BOOK_CAR join b in context.MAS_CAR_TYPE on a.MCT_ID equals b.MCT_ID join c in context.MAS_CAR on a.MCA_ID equals c.MCA_ID join d in context.MAS_CAR_REASON on a.MCR_ID equals d.MCR_ID join e in context.EMP_PROFILE on a.bc_create_by equals e.EMP_ID join f in context.MAS_APPROVE_STATUS on a.bc_status equals f.MAS_ID join g in context.MAS_DESTINATION on a.MDT_ID equals g.MDT_ID where a.bc_create_by.ToString() == userId && f.mas_name == "Approved" select new { Type = "2", Title = d.MCR_NAME + " " + c.MCA_NAME, Start = a.bc_start_date + " " + a.bc_start_time, End = a.bc_stop_date + " " + a.bc_stop_time, Id = a.BC_ID, Color = c.MCA_COLOR, StsText = f.mas_name, Create_by = a.bc_create_by }).ToList(); foreach (var item in queryCar) { dashBoardCalendarViewModel viewModel = new dashBoardCalendarViewModel(); viewModel.id = item.Id.ToString(); viewModel.type = item.Type; viewModel.title = item.Title; viewModel.start = item.Start; viewModel.end = item.End; viewModel.color = item.Color; //if (item.Create_by.ToString() == userId) //{ // result.Add(viewModel); //} result.Add(viewModel); } } } catch (Exception ex) { throw new Exception(ex.Message); } return(result); }
public messageModel insert(benefitsModel value) { messageModel result = new messageModel(); try { using (var context = new StandardCanEntities()) { var _Gapi = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH"); var _Gpath = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH"); JsonPathModel jsonPath = new JsonPathModel(); if (_Gpath != null) { jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel)); } if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "Benefits_insert", update_date = DateTime.Now }); context.SaveChanges(); var dt = DateTime.Now; MAS_BENEFITS benefits = new MAS_BENEFITS(); benefits.mb_title = value.title; benefits.mb_detail = value.detail; if (value.doc != null) { string[] doc = value.doc.Split(','); var docBase64 = doc.Count() > 1 ? doc[1] : doc[0]; byte[] imgbyte = Convert.FromBase64String(docBase64); var guId = Guid.NewGuid().ToString(); var fileName = guId + ".PDF"; string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.benefits), Path.GetFileName(fileName)); if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } using (var stream = new FileStream(path, FileMode.Create)) { stream.Write(imgbyte, 0, imgbyte.Length); } benefits.mb_link_url = fileName; } context.MAS_BENEFITS.Add(benefits); context.SaveChanges(); result.status = "S"; result.message = "Success"; } } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public projectTrainingDetailResult trainingDetail(projectTrainingScheduleModel value) { projectTrainingDetailResult result = new projectTrainingDetailResult(); result.message = new messageModel(); try { using (StandardCanEntities context = new StandardCanEntities()) { //if (String.IsNullOrEmpty(value.user_id)) //{ // throw new Exception("Unauthorized Access"); //} //var userId = JwtHelper.GetUserIdFromToken(value.user_id); //if (String.IsNullOrEmpty(userId)) //{ // throw new Exception("Unauthorized Access"); //} JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "trainingDetail", update_date = DateTime.Now }); context.SaveChanges(); result.data = new projectTrainingDetailDataResult(); result.data.training_item = new List <projectTrainingItemDetailDataResult>(); var _training = context.TRAININGs.SingleOrDefault(a => a.TrainingId.ToString() == value.training_id); //var empList = context.EMP_PROFILE.ToList(); //var departList = context.MAS_DEPARTMENT.ToList(); //List<EMP_PROFILE> empList = null; if (_training != null) { result.data.training_id = _training.TrainingId.ToString(); result.data.training_name = _training.TrainingName; //result.data.date_form = _training.TrainingDateFrom != null ? _training.TrainingDateFrom.Value.ToString("dd/MM/yyyy") : ""; //result.data.date_to = _training.TrainingDateTo != null ? _training.TrainingDateTo.Value.ToString("dd/MM/yyyy") : ""; result.data.date_form = _training.TrainingDateFrom != null?_training.TrainingDateFrom.Value.ToString("yyyy-MM-dd", new System.Globalization.CultureInfo("en-US")) : ""; result.data.date_to = _training.TrainingDateTo != null?_training.TrainingDateTo.Value.ToString("yyyy-MM-dd", new System.Globalization.CultureInfo("en-US")) : ""; result.data.training_status = _training.TrainingStatus.Value.ToString(); var _trainingItem = context.TRAINING_ITEM.Where(a => a.TrainingId.ToString() == value.training_id).ToList(); foreach (var item in _trainingItem) { projectTrainingItemDetailDataResult projectTraining = new projectTrainingItemDetailDataResult(); projectTraining.training_item_id = item.TrainingItemId.ToString(); projectTraining.course_id = item.MAS_COURSE.MCS_ID.ToString(); projectTraining.course_name = item.MAS_COURSE.MCS_NAME; projectTraining.course_type = item.MAS_COURSE.MCS_TYPE; projectTraining.destination_id = item.MAS_DESTINATION.MDT_ID.ToString(); projectTraining.destination_name = item.MAS_DESTINATION.MDT_NAME; projectTraining.item_date = item.TrainingItemDate != null?item.TrainingItemDate.Value.ToString("yyyy-MM-dd", new System.Globalization.CultureInfo("en-US")) : ""; projectTraining.time_start = item.TrainingItemStart; projectTraining.time_stop = item.TrainingItemStop; projectTraining.expert_list = new List <projectTrainingItemDetailExpertDataResult>(); foreach (var expert in item.TRAINING_EXPERT) { projectTrainingItemDetailExpertDataResult detailExpertDataResult = new projectTrainingItemDetailExpertDataResult(); detailExpertDataResult.expert_id = expert.MAS_EXPERT.MEP_ID.ToString(); detailExpertDataResult.expert_name = expert.MAS_EXPERT.MEP_NAME; projectTraining.expert_list.Add(detailExpertDataResult); } projectTraining.expense_list = new List <projectTrainingItemDetailExpenseDataResult>(); double total = 0.00; foreach (var expense in item.TRAINING_EXPENSE) { projectTrainingItemDetailExpenseDataResult itemDetailExpenseDataResult = new projectTrainingItemDetailExpenseDataResult(); total += expense.TrainingExpensePrice != null ? expense.TrainingExpensePrice.Value : 0; itemDetailExpenseDataResult.expense_id = expense.ExpenseId.ToString(); itemDetailExpenseDataResult.expense_name = expense.MAS_EXPENSE.MEXP_NAME; itemDetailExpenseDataResult.expense_price = expense.TrainingExpensePrice.ToString(); projectTraining.expense_list.Add(itemDetailExpenseDataResult); } projectTraining.expense_total = total.ToString(); projectTraining.emp_list = new List <projectTrainingItemDetailEmpDataResult>(); string sql = ""; sql += "select a.TrainingEmpCode emp_code, c.md_name emp_depart, b.emp_code + ' ' + isnull(b.emp_title,'') + b.emp_fname + ' ' + isnull(b.emp_lname,'') emp_name "; sql += " , isnull(b.emp_tel, '') emp_tel, isnull(b.emp_email, '') emp_email "; sql += " , TrainingEmpScore1 emp_score1, TrainingEmpScore2 emp_score2, TrainingEmpScore3 emp_score3, TrainingEmpScore4 emp_score4 "; sql += " , TrainingEmpScore5 emp_score5, TrainingEmpScoreTotal emp_score_total, TrainingEmpResult emp_result "; sql += "from TRAINING_EMP a left join EMP_PROFILE b on a.TrainingEmpCode = b.emp_code "; sql += " left join MAS_DEPARTMENT c on b.emp_depart_2 = c.MD_ID "; sql += "where a.TrainingId = " + value.training_id; sql += " and a.TrainingItemId = " + item.TrainingItemId.ToString(); sql += "order by a.TrainingEmpId "; projectTraining.emp_list = context.Database.SqlQuery <projectTrainingItemDetailEmpDataResult>(sql).ToList(); //if (empList != null) //{ // foreach (var emp in item.TRAINING_EMP) // { // var _emp = empList.SingleOrDefault(a => a.emp_code == emp.TrainingEmpCode); // var _depart = departList.SingleOrDefault(a => a.MD_ID.ToString() == _emp.emp_depart_2); // projectTrainingItemDetailEmpDataResult itemDetailEmpDataResult = new projectTrainingItemDetailEmpDataResult(); // itemDetailEmpDataResult.emp_code = emp.TrainingEmpCode; // itemDetailEmpDataResult.emp_depart = _depart.md_name; // itemDetailEmpDataResult.emp_name = (_emp.emp_title ?? "") + _emp.emp_fname + " " + _emp.emp_lname; // itemDetailEmpDataResult.emp_tel = _emp.emp_tel; // itemDetailEmpDataResult.emp_email = _emp.emp_email; // itemDetailEmpDataResult.emp_score1 = emp.TrainingEmpScore1; // itemDetailEmpDataResult.emp_score2 = emp.TrainingEmpScore2; // itemDetailEmpDataResult.emp_score3 = emp.TrainingEmpScore3; // itemDetailEmpDataResult.emp_score4 = emp.TrainingEmpScore4; // itemDetailEmpDataResult.emp_score5 = emp.TrainingEmpScore5; // itemDetailEmpDataResult.emp_score_total = emp.TrainingEmpScoreTotal; // itemDetailEmpDataResult.emp_result = emp.TrainingEmpResult; // projectTraining.emp_list.Add(itemDetailEmpDataResult); // } //} result.data.training_item.Add(projectTraining); } } result.message.status = "S"; result.message.message = "Success"; } } catch (Exception ex) { result.message.status = "E"; result.message.message = ex.Message.ToString(); } return(result); }
public messageModel importFileScore(string fileType, string fileId, string user_id, HttpPostedFile postedFile) { messageModel result = new messageModel(); try { if (String.IsNullOrEmpty(user_id)) { throw new Exception("Unauthorized Access"); } var userId = user_id; byte[] fileData = null; using (var binaryReader = new BinaryReader(postedFile.InputStream)) { fileData = binaryReader.ReadBytes(postedFile.ContentLength); using (MemoryStream ms2 = new MemoryStream(fileData)) { using (var context = new StandardCanEntities()) { Workbook workbook = new Workbook(); workbook.LoadFromStream(ms2); Worksheet sheet = workbook.Worksheets[0]; int rowCount = sheet.Rows.Length; var chkNull = false; var tokenId = Guid.NewGuid().ToString(); var dt = DateTime.Now; for (var i = 2; i <= rowCount; i++) { if (chkNull) { break; } var data = sheet.Range[i, 1].Value; if (!String.IsNullOrEmpty(data)) { string dmy = sheet.Range[i, 2].Value + "/" + sheet.Range[i, 3].Value + "/" + sheet.Range[i, 4].Value; IMPORT_SCORE _import = new IMPORT_SCORE(); _import.Row_Id = Guid.NewGuid().ToString(); _import.Token_Id = tokenId; _import.Item_No = i - 1; _import.Emp_Code = sheet.Range[i, 1].Value; _import.File_Date = DateTime.ParseExact(dmy, "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture); _import.File_Id = fileId; _import.File_Type = fileType; _import.Emp_Score = string.IsNullOrEmpty(sheet.Range[i, 5].Value) ? 0 : Convert.ToDouble(sheet.Range[i, 5].Value); _import.Create_Date = dt; _import.Create_By = Convert.ToInt32(userId); //_import.Update_Date = dt; _import.Update_By = Convert.ToInt32(userId); context.IMPORT_SCORE.Add(_import); context.SaveChanges(); } else { chkNull = true; break; } } context.sp_update_score(tokenId, userId); } } } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel delete(imageSlideModel value) { messageModel result = new messageModel(); try { using (var context = new StandardCanEntities()) { var _Gapi = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH"); var _Gpath = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH"); JsonPathModel jsonPath = new JsonPathModel(); if (_Gpath != null) { jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel)); } if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "ImageSlide_delete", update_date = DateTime.Now }); context.SaveChanges(); var news = context.IMAGE_SLIDE.SingleOrDefault(a => a.IS_ID.ToString() == value.id); if (news != null) { DirectoryInfo di = new DirectoryInfo(HostingEnvironment.MapPath("~" + jsonPath.imageSlide)); foreach (FileInfo files in di.GetFiles()) { if (files.Name == news.is_url_image) { files.Delete(); } } context.IMAGE_SLIDE.Remove(news); context.SaveChanges(); result.status = "S"; result.message = "Success"; } else { result.status = "E"; result.message = "Data not Found"; } } } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel saveUserRole(RoleViewModel role) { messageModel result = new messageModel(); try { if (String.IsNullOrEmpty(role.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(role.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } using (var context = new StandardCanEntities()) { var dt = DateTime.Now; if (String.IsNullOrEmpty(role.usergroup_id)) { var checkName = context.USER_GROUP.SingleOrDefault(a => a.Group_Name.ToUpper() == role.usergroup_Desc.ToUpper()); if (checkName != null) { throw new Exception("Data is duplicate"); } USER_GROUP uSER_GROUP = new USER_GROUP(); uSER_GROUP.Group_Name = role.usergroup_Desc.ToUpper(); uSER_GROUP.Active = role.active ?? false; context.USER_GROUP.Add(uSER_GROUP); context.SaveChanges(); if (role.program_list != null) { foreach (var item in role.program_list) { USER_ROLE data = new USER_ROLE(); data.Group_ID = uSER_GROUP.Group_ID.ToString(); data.Program_ID = item.program_id; data.Active = role.active ?? false; data.Create_Date = dt; data.Create_By = Convert.ToInt32(userId); data.Update_Date = dt; data.Update_By = Convert.ToInt32(userId); context.USER_ROLE.Add(data); context.SaveChanges(); } } } else { var checkName = context.USER_GROUP.SingleOrDefault(a => a.Group_Name.ToUpper() == role.usergroup_Desc.ToUpper() && a.Group_ID.ToString() != role.usergroup_id); if (checkName != null) { throw new Exception("Data is duplicate"); } var userGroupDetail = context.USER_GROUP.SingleOrDefault(a => a.Group_ID.ToString() == role.usergroup_id); if (userGroupDetail == null) { throw new Exception("Data is not found"); } userGroupDetail.Group_Name = role.usergroup_Desc.ToUpper(); userGroupDetail.Active = role.active ?? false; context.SaveChanges(); var roleOldList = context.USER_ROLE.Where(a => a.Group_ID == role.usergroup_id).ToList(); context.USER_ROLE.RemoveRange(roleOldList); context.SaveChanges(); if (role.program_list != null) { foreach (var item in role.program_list) { USER_ROLE data = new USER_ROLE(); data.Group_ID = userGroupDetail.Group_ID.ToString(); data.Program_ID = item.program_id; data.Active = role.active ?? false; data.Create_Date = dt; data.Create_By = Convert.ToInt32(userId); data.Update_Date = dt; data.Update_By = Convert.ToInt32(userId); context.USER_ROLE.Add(data); context.SaveChanges(); } } } } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel save_status(bookRoomDetailModel value) { messageModel result = new messageModel(); try { System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32)); using (var context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { ID = 1, data_log = json, module = "book_room_save", update_date = DateTime.Now }); context.SaveChanges(); string save_type = ""; if (value.method.Equals("save_cancel")) { save_type = "0"; } else if (value.method.Equals("save_approve")) { save_type = "3"; } else if (value.method.Equals("save_reject")) { save_type = "4"; } else if (value.method.Equals("save_revise")) { ///TODO Draft save_type = "1"; } if (save_type == "3") { var allRoomList = context.BOOK_ROOM.ToList(); var bookingDeatil = allRoomList.SingleOrDefault(a => a.BR_ID.ToString() == value.id); if (bookingDeatil != null) { var dupTime = 0; //var chkSameDate = allRoomList.Where(a => a.br_date == bookingDeatil.br_date && a.MRM_ID == bookingDeatil.MRM_ID && a.br_status == 3).ToList(); //var start_time = DateTime.ParseExact(bookingDeatil.br_start_time, "HH:mm", CultureInfo.InvariantCulture); //var stop_time = DateTime.ParseExact(bookingDeatil.br_stop_time, "HH:mm", CultureInfo.InvariantCulture); //foreach (var item in chkSameDate) //{ // var _itemStart_time = DateTime.ParseExact(item.br_start_time, "HH:mm", CultureInfo.InvariantCulture); // var _itemStop_time = DateTime.ParseExact(item.br_stop_time, "HH:mm", CultureInfo.InvariantCulture); // if(stop_time > _itemStart_time) // { // dupTime++; // } //} if (dupTime == 0) { int ret = context.sp_bookroom_save_status(value.id, save_type, value.remark, userId); result.status = "S"; result.message = ""; } else { throw new Exception("ห้องนี้ในช่วงเวลานี้ได้ถูกจองแล้ว"); } } else { throw new Exception("Data not Found"); } } else { int ret = context.sp_bookroom_save_status(value.id, save_type, value.remark, userId); result.status = "S"; result.message = ""; } } } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel update(projectTrainingScheduleModel value) { messageModel result = new messageModel(); using (var context = new StandardCanEntities()) { var dbContextTransaction = context.Database.BeginTransaction(); try { //if (String.IsNullOrEmpty(value.user_id)) //{ // throw new Exception("Unauthorized Access"); //} //var userId = JwtHelper.GetUserIdFromToken(value.user_id); //if (String.IsNullOrEmpty(userId)) //{ // throw new Exception("Unauthorized Access"); //} JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "Training_update", update_date = DateTime.Now }); context.SaveChanges(); var dt = DateTime.Now; var training = context.TRAININGs.SingleOrDefault(a => a.TrainingId.ToString() == value.training_id); if (training != null) { result.value = training.TrainingId.ToString(); training.TrainingName = value.training_name; //training.TrainingDateFrom = String.IsNullOrEmpty(value.date_form) ? (DateTime?)null : DateTime.ParseExact(value.date_form, "dd/MM/yyyy", CultureInfo.InvariantCulture); //training.TrainingDateTo = String.IsNullOrEmpty(value.date_to) ? (DateTime?)null : DateTime.ParseExact(value.date_to, "dd/MM/yyyy", CultureInfo.InvariantCulture); training.TrainingDateFrom = String.IsNullOrEmpty(value.date_form) ? (DateTime?)null : DateTime.ParseExact(value.date_form, "yyyy-MM-dd", CultureInfo.InvariantCulture); training.TrainingDateTo = String.IsNullOrEmpty(value.date_to) ? (DateTime?)null : DateTime.ParseExact(value.date_to, "yyyy-MM-dd", CultureInfo.InvariantCulture); training.TrainingStatus = value.training_status; //training.CreateBy = Convert.ToInt32(userId); training.CreateDate = dt; //training.UpdateBy = Convert.ToInt32(userId); training.UpdateDate = dt; context.SaveChanges(); var _emp = context.TRAINING_EMP.Where(a => a.TrainingId == training.TrainingId).ToList(); context.TRAINING_EMP.RemoveRange(_emp); context.SaveChanges(); var _expense = context.TRAINING_EXPENSE.Where(a => a.TrainingId == training.TrainingId).ToList(); context.TRAINING_EXPENSE.RemoveRange(_expense); context.SaveChanges(); var _expert = context.TRAINING_EXPERT.Where(a => a.TrainingId == training.TrainingId).ToList(); context.TRAINING_EXPERT.RemoveRange(_expert); context.SaveChanges(); var _training_item = context.TRAINING_ITEM.Where(a => a.TrainingId == training.TrainingId).ToList(); context.TRAINING_ITEM.RemoveRange(_training_item); context.SaveChanges(); foreach (var item in value.training_item) { TRAINING_ITEM training_item = new TRAINING_ITEM(); training_item.TrainingId = training.TrainingId; training_item.TrainingCourseId = !String.IsNullOrEmpty(item.course_id) ? Convert.ToInt32(item.course_id) : (int?)null; training_item.TrainingDestinationId = !String.IsNullOrEmpty(item.destination_id) ? Convert.ToInt32(item.destination_id) : (int?)null; training_item.TrainingItemDate = String.IsNullOrEmpty(item.item_date) ? (DateTime?)null : DateTime.ParseExact(item.item_date, "yyyy-MM-dd", CultureInfo.InvariantCulture); training_item.TrainingItemStart = item.time_start ?? ""; training_item.TrainingItemStop = item.time_stop ?? ""; context.TRAINING_ITEM.Add(training_item); context.SaveChanges(); if (item.expert_list != null) { foreach (var expert in item.expert_list) { if (!String.IsNullOrEmpty(expert.expert_id)) { TRAINING_EXPERT training_expert = new TRAINING_EXPERT(); training_expert.TrainingId = training.TrainingId; training_expert.TrainingItemId = training_item.TrainingItemId; training_expert.ExpertId = Convert.ToInt32(expert.expert_id); context.TRAINING_EXPERT.Add(training_expert); context.SaveChanges(); } } } if (item.expense_list != null) { foreach (var expense in item.expense_list) { if (!String.IsNullOrEmpty(expense.expense_id)) { TRAINING_EXPENSE training_expense = new TRAINING_EXPENSE(); training_expense.TrainingId = training.TrainingId; training_expense.TrainingItemId = training_item.TrainingItemId; training_expense.ExpenseId = Convert.ToInt32(expense.expense_id); training_expense.TrainingExpensePrice = String.IsNullOrEmpty(expense.expense_price) ? 0 : Convert.ToDouble(expense.expense_price); context.TRAINING_EXPENSE.Add(training_expense); context.SaveChanges(); } } } if (item.emp_list != null) { foreach (var emp in item.emp_list) { if (!String.IsNullOrEmpty(emp.emp_code)) { TRAINING_EMP training_emp = new TRAINING_EMP(); training_emp.TrainingId = training.TrainingId; training_emp.TrainingItemId = training_item.TrainingItemId; training_emp.TrainingEmpCode = emp.emp_code; training_emp.TrainingEmpScore1 = emp.emp_score1; training_emp.TrainingEmpScore2 = emp.emp_score2; training_emp.TrainingEmpScore3 = emp.emp_score3; training_emp.TrainingEmpScore4 = emp.emp_score4; training_emp.TrainingEmpScore5 = emp.emp_score5; training_emp.TrainingEmpScoreTotal = emp.emp_score_total; training_emp.TrainingEmpResult = emp.emp_result; context.TRAINING_EMP.Add(training_emp); context.SaveChanges(); } } } } dbContextTransaction.Commit(); result.status = "S"; result.message = "Success"; } else { dbContextTransaction.Rollback(); result.status = "E"; result.message = "Data not found"; } } catch (Exception ex) { dbContextTransaction.Rollback(); result.status = "E"; result.message = ex.Message.ToString(); } } return(result); }
public messageModel save_draft(bookRoomDetailModel value) { messageModel result = new messageModel(); try { System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32)); using (var context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { ID = 1, data_log = json, module = "book_room_save_draft", update_date = DateTime.Now }); context.SaveChanges(); string save_type = "1"; // save_draft if (value.method.Equals("save_send")) { save_type = "2"; } //else if (value.method.Equals("save_revise")) //{ // save_type = "1"; //} int ret = context.sp_bookroom_save(value.id, value.topic, value.date, value.start_time, value.stop_time , value.room_id, value.person_total, value.remark, save_type, userId, myOutputParamInt, value.br_request); if (myOutputParamInt.Value != null) { int r_id = Convert.ToInt32(myOutputParamInt.Value); result.status = "S"; result.message = ""; result.value = r_id.ToString(); value.id = String.IsNullOrEmpty(value.id) ? r_id.ToString() : value.id; } else { result.status = "E"; result.message = ""; } context.sp_bookroom_delete_device(value.id); if (value.device_list != null) { foreach (var item in value.device_list) { if (item.opt) { context.sp_bookroom_insert_device(value.id, item.id); } } } context.sp_bookroom_delete_emp(value.id); if (value.emp_list != null) { foreach (var item in value.emp_list) { context.sp_bookroom_insert_emp(value.id, item.emp_code); } } } } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel save_draft(bookCarDetailModel value) { messageModel result = new messageModel(); try { System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32)); using (var context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } string save_type = "1"; // save_draft if (value.method.Equals("save_send")) { save_type = "2"; if (!String.IsNullOrEmpty(value.start_date)) { var startDate = DateTime.ParseExact(value.start_date + " " + value.stop_time, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); var bfDateNow = DateTime.Now.AddDays(2); if (bfDateNow >= startDate) { throw new Exception("Please book at least 2 days"); } } } else if (value.method.Equals("save_update")) { save_type = ""; if (!String.IsNullOrEmpty(value.start_date)) { var startDate = DateTime.ParseExact(value.start_date + " " + value.stop_time, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); var bfDateNow = DateTime.Now.AddDays(2); if (bfDateNow >= startDate) { throw new Exception("Please book at least 2 days"); } } } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { ID = 1, data_log = json, module = "book_car_save_draft", update_date = DateTime.Now }); context.SaveChanges(); int ret = context.sp_bookcar_save(value.id, value.topic, value.start_date, value.start_time, value.stop_date, value.stop_time, value.person_total, value.car_type_id, value.car_id, value.reason_id, value.dest_id, value.remark, save_type, userId, value.bc_request, myOutputParamInt); if (myOutputParamInt.Value != null) { int r_id = Convert.ToInt32(myOutputParamInt.Value); value.id = r_id.ToString(); } context.sp_bookcar_delete_emp(value.id); if (value.emp_list != null) { foreach (var item in value.emp_list) { context.sp_bookcar_insert_emp(value.id, item.emp_code); } } } result.status = "S"; result.message = ""; result.value = value.id; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel update_emp_score(employeeModel value) { messageModel result = new messageModel(); try { string emp_name = ""; JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); int ret = -1; using (var context = new StandardCanEntities()) { if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } context.interface_log.Add(new interface_log { module = "update_emp_score", data_log = json, update_date = DateTime.Now }); context.SaveChanges(); var emp = context.EMP_PROFILE.Where(p => p.emp_card_no.Equals(value.emp_code)).FirstOrDefault(); if (emp == null) { result.status = "E"; result.message = "รหัสบัตรไม่ถูกต้อง !"; } else { ret = context.sp_update_score_outdoor(value.emp_code, value.date, value.score, value.detail_id, userId); emp_name = (emp.emp_fname ?? "") + " " + emp.emp_lname ?? ""; } } if (ret == -1) { result.status = "E"; result.message = "รหัสบัตรไม่ถูกต้อง !"; } else { result.status = "S"; result.message = "บันทึกคะแนนของ " + emp_name + " สำเร็จ"; } } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public newsDataResultModel search(newsModel value) { newsDataResultModel result = new newsDataResultModel(); result.message = new messageModel(); try { using (StandardCanEntities context = new StandardCanEntities()) { var _Gapi = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH"); var _Gpath = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH"); JsonPathModel jsonPath = new JsonPathModel(); if (_Gpath != null) { jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel)); } if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "News_search", update_date = DateTime.Now }); context.SaveChanges(); var data = context.NEWS.Where(a => a.nw_topic.Contains(value.topic)).ToList(); result.newsData = new List <newsModel>(); foreach (var item in data) { newsModel news = new newsModel(); news.id = item.NW_ID.ToString(); news.newsTypeId = item.nw_type.ToString(); if (news.newsTypeId == "1") { news.newsTypeName = "ข่าวสาร"; } else if (news.newsTypeId == "2") { news.newsTypeName = "กิจกรรม"; } else if (news.newsTypeId == "3") { news.newsTypeName = "vdo"; } news.topic = item.nw_topic; news.detail = item.nw_detail; news.url = !String.IsNullOrEmpty(item.nw_image) ? _Gapi.GGC_VAL + jsonPath.news + item.nw_image : null; news.urlVdo = item.nw_vdo; result.newsData.Add(news); } result.message.status = "S"; result.message.message = "Success"; } } catch (Exception ex) { result.message.status = "E"; result.message.message = ex.Message.ToString(); } return(result); }
public messageModel uploadFile(employeeModel value) { messageModel result = new messageModel(); try { using (var context = new StandardCanEntities()) { var dt = DateTime.Now; var _Gapi = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH"); var _Gpath = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH"); JsonPathModel jsonPath = new JsonPathModel(); if (_Gpath != null) { jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel)); } if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "Employee_uploadFile", update_date = dt }); context.SaveChanges(); if (value.img != null) { string[] img = value.img.Split(','); var imgBase64 = img.Count() > 1 ? img[1] : img[0]; byte[] imgbyte = Convert.FromBase64String(imgBase64); var guId = Guid.NewGuid().ToString(); var fileName = guId + ".JPG"; string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.employee), Path.GetFileName(fileName)); if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } using (var stream = new FileStream(path, FileMode.Create)) { stream.Write(imgbyte, 0, imgbyte.Length); } var empDetail = context.EMP_PROFILE.SingleOrDefault(a => a.emp_code == value.emp_code); if (empDetail != null) { empDetail.emp_image = fileName; context.SaveChanges(); } else { throw new Exception("Data not found"); } } } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel insert(newsModel value) { messageModel result = new messageModel(); try { using (var context = new StandardCanEntities()) { var _Gapi = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH"); var _Gpath = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH"); JsonPathModel jsonPath = new JsonPathModel(); if (_Gpath != null) { jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel)); } if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "News_insert", update_date = DateTime.Now }); context.SaveChanges(); var dt = DateTime.Now; NEWS news = new NEWS(); news.nw_type = value.newsTypeId != null?Convert.ToInt32(value.newsTypeId) : (int?)null; news.nw_topic = value.topic; news.nw_detail = value.detail; news.nw_status = 1; if (news.nw_type == 1 || news.nw_type == 2) { if (value.img != null) { string[] img = value.img.Split(','); var imgBase64 = img.Count() > 1 ? img[1] : img[0]; byte[] imgbyte = Convert.FromBase64String(imgBase64); var guId = Guid.NewGuid().ToString(); var fileName = guId + ".JPG"; string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.news), Path.GetFileName(fileName)); if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } using (var stream = new FileStream(path, FileMode.Create)) { stream.Write(imgbyte, 0, imgbyte.Length); } news.nw_image = fileName; } } else if (news.nw_type == 3) { news.nw_vdo = value.urlVdo; } news.nw_date = dt; news.nw_update_by = Convert.ToInt32(userId); news.nw_update_date = dt; context.NEWS.Add(news); context.SaveChanges(); result.status = "S"; result.message = "Success"; } } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel insert(imageSlideModel value) { messageModel result = new messageModel(); try { using (var context = new StandardCanEntities()) { var _Gapi = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH"); var _Gpath = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH"); JsonPathModel jsonPath = new JsonPathModel(); if (_Gpath != null) { jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel)); } if (String.IsNullOrEmpty(value.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(value.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(value); context.interface_log.Add(new interface_log { data_log = json, module = "ImageSlide_insert", update_date = DateTime.Now }); context.SaveChanges(); var dt = DateTime.Now; IMAGE_SLIDE news = new IMAGE_SLIDE(); news.is_status = 1; if (value.img != null) { string[] img = value.img.Split(','); var imgBase64 = img.Count() > 1 ? img[1] : img[0]; byte[] imgbyte = Convert.FromBase64String(imgBase64); var guId = Guid.NewGuid().ToString(); var fileName = guId + ".JPG"; string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.imageSlide), Path.GetFileName(fileName)); if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } using (var stream = new FileStream(path, FileMode.Create)) { stream.Write(imgbyte, 0, imgbyte.Length); } news.is_url_image = fileName; news.is_url_link = value.url; news.is_update_date = dt; news.is_update_by = Convert.ToInt32(userId); var lastOrder = context.IMAGE_SLIDE.OrderByDescending(u => u.is_order_by).FirstOrDefault(); news.is_order_by = (short?)(lastOrder != null ? (Convert.ToInt32(lastOrder.is_order_by) + 1) : 0); context.IMAGE_SLIDE.Add(news); context.SaveChanges(); } else { throw new Exception("Image not Found"); } result.status = "S"; result.message = "Success"; } } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }
public messageModel importUserRole(string fileType, string fileId, string user_id, HttpPostedFile postedFile) { messageModel result = new messageModel(); try { if (String.IsNullOrEmpty(user_id)) { throw new Exception("Unauthorized Access"); } var userId = user_id; //if (String.IsNullOrEmpty(userId)) //{ // throw new Exception("Unauthorized Access"); //} byte[] fileData = null; using (var binaryReader = new BinaryReader(postedFile.InputStream)) { fileData = binaryReader.ReadBytes(postedFile.ContentLength); using (MemoryStream ms2 = new MemoryStream(fileData)) { using (var context = new StandardCanEntities()) { Workbook workbook = new Workbook(); workbook.LoadFromStream(ms2); Worksheet sheet = workbook.Worksheets[0]; int rowCount = sheet.Rows.Length; var chkNull = false; var tokenId = Guid.NewGuid().ToString(); var dt = DateTime.Now; for (var i = 2; i <= rowCount; i++) { if (chkNull) { break; } var data = sheet.Range[i, 1].Value; if (!String.IsNullOrEmpty(data)) { IMPORT_DATA _import = new IMPORT_DATA(); _import.Row_Id = Guid.NewGuid().ToString(); _import.Token_Id = tokenId; _import.Item_No = i - 1; //_import.Id_Card = sheet.Range[i, 1].Value; _import.Emp_Code = sheet.Range[i, 1].Value; //_import.Emp_Name = sheet.Range[i, 3].Value; //_import.Emp_Dep = sheet.Range[i, 4].Value; _import.Emp_Position = sheet.Range[i, 2].Value; _import.Create_Date = dt; _import.Create_By = Convert.ToInt32(userId); _import.Update_Date = dt; _import.Update_By = Convert.ToInt32(userId); context.IMPORT_DATA.Add(_import); context.SaveChanges(); } else { chkNull = true; break; } } context.sp_update_card(fileType + tokenId); } } } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }