Beispiel #1
0
        public void MessageUs([FromBody] messageModel message)
        {
            string       fromAddress  = "*****@*****.**";
            string       toAddress    = "*****@*****.**";
            const string fromPassword = "******";
            string       body         = string.Format("From: {0}, Email: {1}\n\n{2}", message.name, message.email, message.messageContent);
            var          smtp         = new System.Net.Mail.SmtpClient();

            {
                smtp.Host           = "relay-hosting.secureserver.net";
                smtp.Port           = 25;
                smtp.EnableSsl      = false;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials    = new NetworkCredential(fromAddress, fromPassword);
                smtp.Timeout        = 20000;
            }
            try
            {
                smtp.Send(fromAddress, toAddress, "Message from TAI", body);
            }
            catch (Exception e)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
        }
Beispiel #2
0
        public messageModel update(projectModel value)
        {
            messageModel result = new messageModel();

            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");
                    }

                    int ret = context.sp_project_update_v2(value.prj_id, value.prj_name, value.start_date, value.stop_date, value.prj_detail, value.prj_status, userId);
                }

                result.status  = "S";
                result.message = "";
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Beispiel #3
0
        public ActionResult ContactUsResult(messageModel message)
        {
            string       fromAddress  = "*****@*****.**";
            string       toAddress    = "*****@*****.**";
            const string fromPassword = "******";
            string       body         = string.Format("From: {0}, {1}\n\n{2}", message.name, message.email, message.messageContent);
            var          smtp         = new System.Net.Mail.SmtpClient();

            {
                smtp.Host           = "smtpout.secureserver.net";
                smtp.Port           = 80;
                smtp.EnableSsl      = false;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials    = new NetworkCredential(fromAddress, fromPassword);
                smtp.Timeout        = 20000;
            }
            try
            {
                smtp.Send(fromAddress, toAddress, "Message for TAI", body);
            }
            catch (Exception e)
            {
                //ViewBag.Result = "There was an error sending your message. Please try again later.";
                ViewBag.Result = e.Message;
                return(View());
            }
            ViewBag.Result = "Your message has been delivered! Thank you for contacting us. We will get back to you as soon as we can.";
            return(View());
        }
        public messageModel delete(carModel value)
        {
            messageModel result = new messageModel();

            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");
                    }

                    int ret = context.sp_car_delete(value.id, userId);
                }

                result.status  = "S";
                result.message = "";
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
        // GET api/HelloWorld
        public string Get()
        {
            messageModel hw = new messageModel();

            //this value could be drawn from a dynamic datasource.
            hw.Message = "Hello World!";

            return(hw.Message);
        }
Beispiel #6
0
        public messageModel insert(projectFormularModel value)
        {
            messageModel result = new messageModel();

            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");
                }

                System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));
                using (var context = new StandardCanEntities())
                {
                    int ret        = context.sp_formular_insert(value.fml_name, value.fml_type, value.fml_input_type, value.user_id, myOutputParamInt);
                    int countRange = value.formularRange.Count();
                    for (int i = 0; i < countRange; i++)
                    {
                        int ret2 = context.sp_formularrange_insert(ret.ToString(), value.formularRange[i].fml_range_no, value.formularRange[i].fml_range_score, value.formularRange[i].fml_range_display, value.user_id, myOutputParamInt);
                    }

                    int countvalue = value.formularValue.Count();
                    for (int i = 0; i < countvalue; i++)
                    {
                        int ret2 = context.sp_formularvalue_insert(ret.ToString(), value.formularValue[i].fmlv_orderby, value.formularValue[i].fmlv_value, value.formularValue[i].fmlv_text, value.user_id, myOutputParamInt);
                    }
                }


                if (myOutputParamInt.Value != null)
                {
                    int r_id = Convert.ToInt32(myOutputParamInt.Value);
                    result.status  = "S";
                    result.message = "";
                    result.value   = r_id.ToString();
                }
                else
                {
                    result.status  = "E";
                    result.message = "";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.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);
        }
Beispiel #8
0
        // GET: message
        public ActionResult createMessage()
        {
            var id = vendorId(User.Identity.Name);


            messageModel tempmodel = new messageModel();

            tempmodel.detail   = Getarea(id);
            tempmodel.vendorID = id;
            // return View(detail);
            return(View(tempmodel));
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            messageModel hw = new messageModel();

            //setting the Message here, but the model value could be assigned from an external datasource.
            hw.Message = "Hello World!";

            Console.WriteLine(hw.Message);

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Beispiel #10
0
        public ActionResult sendFeedback(string message, int pollID, int questID)
        {
            // Basic check to see if the user is Authenticated.
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            int uid = (int)Session["uid"];

            messageModel msg = new messageModel();
            msg.sendFeedback(message, uid, pollID, questID);

            return RedirectToAction("RegisterUserSuccess", "User");
        }
Beispiel #11
0
        public messageModel getUploadFile(employeeModel value)
        {
            messageModel result = 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");
                    }
                    var empDetail = context.EMP_PROFILE.SingleOrDefault(a => a.emp_code == value.emp_code);
                    if (empDetail != null)
                    {
                        string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.employee),
                                                   Path.GetFileName(empDetail.emp_image));
                        byte[] bytes = File.ReadAllBytes(path);
                        result.value = Convert.ToBase64String(bytes);
                    }
                    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(carModel value)
        {
            messageModel result = new messageModel();

            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");
                }

                System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));
                using (var context = new StandardCanEntities())
                {
                    //int ret = context.sp_car_insert(value.car_type, value.name, value.detail, userId, myOutputParamInt);
                }

                if (myOutputParamInt.Value != null)
                {
                    int r_id = Convert.ToInt32(myOutputParamInt.Value);
                    result.status  = "S";
                    result.message = "";
                    result.value   = r_id.ToString();
                }
                else
                {
                    result.status  = "E";
                    result.message = "";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Beispiel #13
0
        public bool sendMessage(messageModel msgModel)
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("Title", msgModel.Title);
            dict.Add("Content", msgModel.msg);
            SendMessageModel model = new SendMessageModel();

            model.TemplateNo = msgModel.TemplateNo;
            model.Receiver   = msgModel.Receiver;
            model.Parameter  = dict;
            model.SendTime   = DateTime.Now;
            //组装JOSN 数据
            List <SendMessageModel> list = new List <SendMessageModel>();

            list.Add(model);
            //组装JOSN数据
            var jsonModel = new
            {
                Title        = msgModel.Title,
                Body         = list,
                MerchaanNo   = AppConfig.MessageMerchantNo,
                ClientSource = "PC",
                ClientSystem = "DM-web",
                Version      = 1,
                TimeStamp    = DateTime.Now
            };
            string json    = JsonProvider.ToJson(jsonModel);
            string sign    = MD5Provider.Encode(json + AppConfig.MessageKey);
            var    request = new Winner.Framework.Utils.Network.HttpRequestProvider();

            request.SetUrl(AppConfig.MessageUrl)//请求接口地址
            .AddParameter("Json", json)
            .AddParameter("Sign", sign);

            var jsonResult = request.POST();

            if (!jsonResult.Success)
            {
                return(false);
            }
            return(true);
        }
Beispiel #14
0
        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 messageModel workListCancelsSubmit(dashBoardModel value)
        {
            messageModel result = new messageModel();

            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");
                    }

                    foreach (var item in value.select_room_list)
                    {
                        int ret = context.sp_worklist_submit(userId, "0", "1", item, value.remark);
                    }
                    foreach (var item in value.select_car_list)
                    {
                        int ret = context.sp_worklist_submit(userId, "0", "2", item, value.remark);
                    }

                    //int ret = context.sp_room_update(value.id, value.code, value.name, userId);
                }

                result.status  = "S";
                result.message = "";
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Beispiel #16
0
        public messageModel delete(nodeModel value)
        {
            messageModel result = new messageModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    int ret = context.sp_node_delete(value.id, value.user_id);
                }

                result.status  = "S";
                result.message = "";
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Beispiel #17
0
        public ActionResult createMessage(messageModel m)
        {
            var       context = new promoLacDbEntities();
            messages_ obj     = new messages_();

            foreach (var x in m.areaName)
            {
                obj.vendorID           = m.vendorID;
                obj.messageDescription = m.messageDescription;
                obj.messageTitle       = m.messageTitle;
                obj.areaId             = getAreaId(x);
                obj.messageStatus      = "s";

                context.messages_.Add(obj);
                context.SaveChanges();

                tempMessage objM = new tempMessage();


                objM.notificationStatus      = "s";
                objM.notificationAreaId      = obj.areaId.ToString();
                objM.notificationDescription = obj.messageDescription;
                objM.notificationTitle       = obj.messageTitle;
                objM.notificationTime        = DateTime.Now.ToString();
                objM.notificationId          = obj.messageId.ToString();
                IFirebaseConfig mes = new FirebaseConfig
                {
                    AuthSecret = "CwnE0VGXMqxNxcY5YSWVNcL7IAM3hfqRuSiNjWm5",
                    BasePath   = "https://xdadeveloperes.firebaseio.com/"
                };

                IFirebaseClient mfc;
                mfc = new FireSharp.FirebaseClient(mes);

                var set = mfc.Set(@"Messages/" + obj.messageId, objM);
            }

            return(Json(new { success = true, message = "dddd" }, JsonRequestBehavior.AllowGet));
        }
        public messageModel save_Temporary(empCheckInModel value)
        {
            messageModel result = new messageModel();

            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");
                    }

                    if (value.data != null)
                    {
                        foreach (var item in value.data)
                        {
                            context.sp_emp_temporary_save(userId, item.id, item.emp_code, item.start_date, item.stop_date);
                        }
                    }
                }

                result.status  = "S";
                result.message = "";
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        public messageModel tab_behavior_export(employeeModel value)
        {
            messageModel result = new messageModel();

            StandardCanEntities context = new StandardCanEntities();

            try
            {
                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");
                }

                var dataList = context.sp_emp_profile_tabbehavior_search_v2(value.emp_code).ToList();

                if (dataList != null && dataList.Count() > 0)
                {
                    string file_name = string.Format("emp_behavior_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss"));
                    string file_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileExport", file_name);

                    string file_path_folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileExport");
                    bool   exists           = System.IO.Directory.Exists(file_path_folder);

                    if (!exists)
                    {
                        var fileCreate = System.IO.Directory.CreateDirectory(file_path_folder);
                    }

                    FileInfo excelFile = new FileInfo(file_path);
                    using (ExcelPackage excel = new ExcelPackage(excelFile))
                    {
                        string         sheetName  = "data";
                        int            row        = 1;
                        ExcelWorksheet wsTemplate = excel.Workbook.Worksheets.Add(sheetName);
                        wsTemplate.Cells[row, 1].Value = "ลำดับ";
                        wsTemplate.Cells[row, 2].Value = "ปี";
                        wsTemplate.Cells[row, 3].Value = "วันที่";
                        wsTemplate.Cells[row, 4].Value = "รายละเอียด";
                        wsTemplate.Cells[row, 5].Value = "คะแนน";

                        row++;
                        foreach (var item in dataList)
                        {
                            wsTemplate.Cells[row, 1].Value = item.no;
                            wsTemplate.Cells[row, 2].Value = item.year;
                            wsTemplate.Cells[row, 3].Value = item.date;
                            wsTemplate.Cells[row, 4].Value = item.detail;
                            wsTemplate.Cells[row, 5].Value = item.score;
                            row++;
                        }

                        wsTemplate.Cells.AutoFitColumns();
                        excel.Save();
                    }

                    result.status  = "S";
                    result.message = "Success";
                    result.value   = _Gapi.GGC_VAL + jsonPath.fileExport + file_name;
                }
                else
                {
                    result.status  = "E";
                    result.message = "not found data!";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
        public messageModel workListApproveSubmit(dashBoardModel value)
        {
            messageModel result = new messageModel();

            try
            {
                result.status  = "S";
                result.message = "";

                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");
                    }

                    System.Data.Entity.Core.Objects.ObjectParameter myOutputParam_sts = new System.Data.Entity.Core.Objects.ObjectParameter("r_sts", typeof(String));
                    System.Data.Entity.Core.Objects.ObjectParameter myOutputParam_msg = new System.Data.Entity.Core.Objects.ObjectParameter("r_msg", typeof(String));


                    System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));
                    foreach (var item in value.select_room_list)
                    {
                        context.sp_bookroom_availability_in(item, myOutputParam_sts, myOutputParam_msg);
                        if (myOutputParam_sts.Value != null)
                        {
                            if (myOutputParam_sts.Value.ToString() == "E")
                            {
                                result.status   = "E";
                                result.message += (myOutputParam_msg.Value == null ? "" : myOutputParam_msg.Value.ToString());
                            }
                            else
                            {
                                context.sp_worklist_submit(userId, "1", "1", item, null);
                            }
                        }
                    }
                    foreach (var item in value.select_car_list)
                    {
                        context.sp_bookcar_availability_in(item, myOutputParam_sts, myOutputParam_msg);
                        if (myOutputParam_sts.Value != null)
                        {
                            if (myOutputParam_sts.Value.ToString() == "E")
                            {
                                result.status   = "E";
                                result.message += (myOutputParam_msg.Value == null ? "" : myOutputParam_msg.Value.ToString());
                            }
                            else
                            {
                                context.sp_worklist_submit(userId, "1", "2", item, null);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
        public messageModel save(projectCourseModel value)
        {
            messageModel result = new messageModel();

            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");
                }

                System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));

                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.file_base64))
                    {
                        string[] doc       = value.file_base64.Split(',');
                        var      imgBase64 = doc.Count() > 1 ? doc[1] : doc[0];
                        byte[]   imgbyte   = Convert.FromBase64String(imgBase64);
                        var      guId      = Guid.NewGuid().ToString();
                        var      fileName  = guId + ".PDF";
                        string   path      = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.projectCourse),
                                                          Path.GetFileName(fileName));
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        DirectoryInfo di = new DirectoryInfo(HostingEnvironment.MapPath("~" + jsonPath.projectCourse));
                        foreach (FileInfo files in di.GetFiles())
                        {
                            if (files.Name == value.file_name)
                            {
                                files.Delete();
                            }
                        }
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            stream.Write(imgbyte, 0, imgbyte.Length);
                        }
                        value.file_name = fileName;
                    }
                    else if (String.IsNullOrEmpty(value.file_url))
                    {
                        string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.projectCourse));
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        DirectoryInfo di = new DirectoryInfo(HostingEnvironment.MapPath("~" + jsonPath.projectCourse));
                        foreach (FileInfo files in di.GetFiles())
                        {
                            if (files.Name == value.file_name)
                            {
                                files.Delete();
                            }
                        }
                        value.file_name = null;
                    }

                    int ret = context.sp_project_course_save_v2(value.id, value.project_id, value.course_id, value.course_name, value.formula_id, value.location_id, value.expert_id, value.file_name, value.file_base64, value.remark, value.score1, value.score2, value.score3, value.score4, value.score5, userId, value.status_id, myOutputParamInt);
                }


                if (myOutputParamInt.Value != null)
                {
                    int r_id = Convert.ToInt32(myOutputParamInt.Value);
                    result.status  = "S";
                    result.message = "";
                    result.value   = r_id.ToString();
                }
                else
                {
                    result.status  = "E";
                    result.message = "";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Beispiel #25
0
        public ActionResult sendPrivateMessage(string msg, int USER_LIST)
        {
            // Basic check to see if the user is Authenticated.
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                buildSelectList();
                return RedirectToAction("Index", "Home");
            }
            int uid = (int)Session["uid"];

            if (msg.Equals(""))
            {
                ViewData["edited"] = "Please do not send blank messages";
                buildSelectList();
                return View();
            }
            else if (msg.Length > 255)
            {
                ViewData["edited"] = "Message is too long, maximimum length allowed is 255";
                buildSelectList();
                return View();
            }

            messageModel messageModel = new messageModel();
            messageModel.sendMessage(msg, uid, USER_LIST);

            return RedirectToAction("sendMessageSuccess");
        }
Beispiel #26
0
        public messageModel save(projectFormularModel value)
        {
            messageModel result = new messageModel();

            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");
                }

                string fml_id = "";
                value.fml_id = value.fml_id == "0" ? "" : value.fml_id;
                System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt        = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));
                System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt_detail = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));
                using (var context = new StandardCanEntities())
                {
                    int ret = context.sp_formular_save(value.fml_id, value.fml_type, value.fml_name, value.fml_input_type, userId, myOutputParamInt);

                    if (myOutputParamInt.Value != null)
                    {
                        int r_id = Convert.ToInt32(myOutputParamInt.Value);
                        fml_id = r_id.ToString();
                    }

                    if (value.range != null)
                    {
                        foreach (var item in value.range)
                        {
                            int ret2 = context.sp_formularrange_insert(fml_id, item.no, item.score, item.display, userId, myOutputParamInt_detail);
                        }
                    }

                    if (value.value != null)
                    {
                        int no = 0;
                        foreach (var item in value.value)
                        {
                            no++;
                            int ret2 = context.sp_formularvalue_insert(fml_id, no.ToString(), item.value, item.text, userId, myOutputParamInt_detail);
                        }
                    }
                }

                result.status  = "S";
                result.message = "";
                result.value   = fml_id;
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Beispiel #27
0
        public ActionResult StartSyncSession(String load)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_USER)
            {
                return RedirectToAction("Invalid", "Home");
            }

            int userid = (int)Session["uid"];
            int pollid = (int)Session["syncPollId"];

            int sessionid = (int)Session["syncSessionId"];
            Session["numOfPossibleAnswers"] = 2;

            int currentQuestionid = (int)Session["syncCurrentQuestionId"];
            Boolean isOpen = true;

            int uid = (int)Session["uid"];
            string message = Request["msg"].ToString();
            if (!message.Equals(""))
            {
                messageModel msgModel = new messageModel();
                msgModel.sendFeedback(message, uid, pollid, currentQuestionid);
            }

            PollAndQuestions pollAndQuestionModel = new PollAndQuestions();
            pollAndQuestionModel.sessionData = new pollModel().displaySessionDetails(sessionid);

            List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid);
            pollAndQuestionModel.questionData = new questionModel().getQuestion(currentQuestionid);
            pollAndQuestionModel.answerData = new answerModel().displayAnswers(currentQuestionid);

            if (pollAndQuestionModel.questionData.questiontype >= 3)
            {
                // If this is a normal MCQ
                if (pollAndQuestionModel.questionData.questiontype < 6)
                {
                    int selectedAnswer = Convert.ToInt32(Request["MCQAnswer"]);
                    if (selectedAnswer != 0)
                    {
                        new responseModel().createMCQResponse(userid, selectedAnswer, sessionid);

                    }
                    else
                    {
                        String error = "webpollingError" + "," + "Please provide your answer(s)";
                        TempData["webpollingError"] = error;
                        return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid });
                    }
                }
                else if (pollAndQuestionModel.questionData.questiontype == 6)
                {
                    String selectedAnswer = Request["RankingAnswerList"];
                    Boolean redundant = isRedundant(selectedAnswer);
                    Boolean empty = isEmpty(selectedAnswer);

                    if (!redundant && !empty)
                    {
                        String[] answers = selectedAnswer.Split(',');
                        for (int i = 0; i < answers.Count(); i++)
                        {
                            int preferencenumber = i;
                            try
                            {
                                new responseModel().createRankingResponse(userid, Convert.ToInt32(answers[i]), sessionid, preferencenumber + 1);
                            }
                            catch (Exception e)
                            {
                                throw (e);
                            }
                        }
                    }
                    // If any of the inputs are the same value
                    else if (redundant && !empty)
                    {
                        String error = "webpollingError" + "," + "Each answer has to be unique";
                        TempData["webpollingError"] = error;
                        return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid });
                    }

                    else
                    {
                        String error = "webpollingError" + "," + "Please provide your answer(s)";
                        TempData["webpollingError"] = error;
                        return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid });
                    }

                }
            }
            else if (pollAndQuestionModel.questionData.questiontype <= 2)
            {
                Boolean isValid = true;
                String selectedAnswer = Request["ShortQuestionAnswer"];

                if (selectedAnswer == "" || selectedAnswer == null)
                {
                    isValid = false;
                    String error = "webpollingError" + "," + "Please provide your answer(s)";
                    TempData["webpollingError"] = error;
                    return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid });
                }
                else if (pollAndQuestionModel.questionData.questiontype == 1 && !Regex.IsMatch(selectedAnswer, @"^\d+$"))
                {
                    isValid = false;
                    String error = "webpollingError" + "," + "Only numeric answer is allowed";
                    Session["shortAnswer"] = "";
                    TempData["webpollingError"] = error;
                    return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid });
                }
                else if (pollAndQuestionModel.questionData.questiontype == 2 && Regex.IsMatch(selectedAnswer, @"^\d+$"))
                {
                    isValid = false;
                    String error = "webpollingError" + "," + "Only alphanumeric answer is not allowed";
                    Session["shortAnswer"] = "";
                    TempData["webpollingError"] = error;
                    return RedirectToAction("StartSyncSession", new { sessionid = sessionid, pollid = pollid });
                }
                if (isValid)
                {
                    AnswerShortAnswerQuestion(selectedAnswer, sessionid, (int)Session["uid"], currentQuestionid);
                }
                else
                {
                    return RedirectToAction("StartSyncSession", new { sessionid = sessionid  ,pollid = pollid});
                }
            }

            while (isOpen)
            {
                int databaseCurrentQuestion = new pollModel().displaySessionDetails(sessionid)[0].currentquestion;
                // If the poll is closed by Poll Master, redirect them to a thank you page.
                if (currentQuestionid != databaseCurrentQuestion)
                {

                    if (databaseCurrentQuestion == 0)
                    {
                        isOpen = false;

                    }
                    //else if (databaseCurrentQuestion == -1)
                    //{
                    //    Session["showGraph"] = true;
                    //    //Response.Write("<SCRIPT LANGUAGE=\"JavaScript\">\n");
                    //    //Response.Write("window.open( \"\/PopUp\/Popup.html\", \"\", \"width=300, height=100\")");
                    //    //Response.Write("<\/script>");
                    //}
                    else
                    {
                        Session["showGraph"] = false;
                        pollAndQuestionModel.sessionData = new pollModel().displaySessionDetails(sessionid);
                        pollAndQuestionModel.questionData = new questionModel().getQuestion(databaseCurrentQuestion);
                        List<answerModel> temp = new answerModel().displayAnswers(databaseCurrentQuestion);
                        pollAndQuestionModel.answerData = temp;
                        List<answerModel> sorted = pollAndQuestionModel.answerData;
                        Session["syncCurrentQuestionId"] = databaseCurrentQuestion;

                        if (pollAndQuestionModel.questionData.questiontype == 6)
                        {
                            Session["numOfPossibleAnswers"] = pollAndQuestionModel.questionData.numberofresponses;
                            buildPlainSelectList(sorted);
                        }

                        isOpen = new pollModel().isOpen(sessionid);
                        return View(pollAndQuestionModel);
                    }
                }
                else if (currentQuestionid == databaseCurrentQuestion)
                {
                    isOpen = new pollModel().isOpen(sessionid);
                    // This doesnt get displayed - 8 October
                }

                if (!isOpen)
                {
                    break;
                }
                else
                {

                    System.Threading.Thread.Sleep(200);
                }

                //return View(pollAndQuestionModel);

            }
            // When the session is closed, redirect the user somewhere *sighhhhhhh
            return RedirectToAction("ConfirmationPage", new { sessionid = sessionid, pollid = pollid });
        }
Beispiel #28
0
        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 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);
        }
Beispiel #30
0
        public ActionResult AboutUs()
        {
            messageModel message = new messageModel();

            return(View(message));
        }
        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);
        }
Beispiel #32
0
        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);
        }
Beispiel #33
0
        public ActionResult Index()
        {
            messageModel message = new messageModel();

            return(View(message));
        }
Beispiel #34
0
        public ActionResult StartAsyncSession(String button)
        {
            if (Session["uid"] == null || Session["uid"].ToString().Equals(""))
            {
                return RedirectToAction("Index", "Home");
            }
            if ((int)Session["user_type"] < User_Type.POLL_USER)
            {
                return RedirectToAction("Invalid", "Home");
            }

            PollAndQuestions pollAndQuestionModel = new PollAndQuestions();
            int sessionid = (int)Session["currentWebpollingSessionid"];
            int pollid = (int)Session["currentWebpollingPollid"];
            int questnum = (int)Session["currentQuestionNumber"];

            List<questionModel> allquestion = (List<questionModel>)Session["AllQuestion"];
            int currentquestion = allquestion[questnum].questionid;

            int uid = (int)Session["uid"];
            string message = Request["msg"].ToString();
            if (!message.Equals(""))
            {
                messageModel msgModel = new messageModel();
                msgModel.sendFeedback(message, uid, pollid, currentquestion);
            }

            Session["selectedAnswer"] = "";

            // if the user is currently answering an MCQ
            if (allquestion[questnum].questiontype >= 3){
                // If this is a normal MCQ
                if (allquestion[questnum].questiontype < 6)
                {
                    int selectedAnswer = Convert.ToInt32(Request["MCQAnswer"]);
                    if (selectedAnswer != null)
                    {

                        AnswerMultipleChoiceQuestion(selectedAnswer, sessionid, (int)Session["uid"], currentquestion);

                        List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid);
                        if (button == "Previous Question")
                        {
                            Session["currentQuestionNumber"] = questnum - 1;
                            int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid;
                            setNextAnswer(questnum + 1, nextquestion, sessionid, (int)Session["uid"]);
                        }

                        // if its the last question, then submit/ update answer but stay on the same question
                        else if (button == "Submit Last Answer")
                        {
                            Session["currentQuestionNumber"] = questnum;
                            Session["selectedAnswer"] = Request["MCQAnswer"];
                            Session["completed"] = "Thank you, you have completed all of the questions in this session.";
                        }
                        // its the next button
                        else
                        {
                            Session["currentQuestionNumber"] = questnum + 1;
                            int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid;
                            setNextAnswer(questnum - 1, nextquestion, sessionid, (int)Session["uid"]);
                        }
                    }

                    // if the user hasnt answered anything, then display error and ask em to answer it NAO
                    else
                    {
                        String error = "webpollingError" + "," + "Please provide your answer(s)";
                        TempData["webpollingError"] = error;

                    }
                }

                // Else, it must be a ranking MCQ where a number of answers allowed is > 1
                else if (allquestion[questnum].questiontype == 6)
                {
                    String selectedAnswer = Request["RankingAnswerList"];
                    Boolean redundant = isRedundant(selectedAnswer);
                    Boolean empty = isEmpty(selectedAnswer);

                    if (!redundant && !empty)
                    {
                        AnswerRankingQuestion(selectedAnswer, sessionid, (int)Session["uid"], currentquestion);

                        List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid);
                        if (button == "Previous Question")
                        {
                            Session["currentQuestionNumber"] = questnum - 1;
                            int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid;
                            setNextAnswer(questnum + 1, nextquestion, sessionid, (int)Session["uid"]);
                        }

                        // if its the last question, then submit/ update answer but stay on the same question
                        else if (button == "Submit Last Answer")
                        {
                            Session["currentQuestionNumber"] = questnum;
                            Session["selectedAnswer"] = Request["MCQAnswer"];
                            Session["completed"] = "Thank you, you have completed all of the questions in this session.";
                        }
                        // its the next button
                        else
                        {
                            Session["currentQuestionNumber"] = questnum + 1;
                            int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid;
                            setNextAnswer(questnum - 1, nextquestion, sessionid, (int)Session["uid"]);
                        }
                    }
                    // If any of the inputs are the same value
                    else if (redundant && !empty)
                    {
                        String error = "webpollingError" + "," + "Each answer has to be unique";
                        TempData["webpollingError"] = error;

                    }

                    else
                    {
                        String error = "webpollingError" + "," + "Please provide your answer(s)";
                        TempData["webpollingError"] = error;
                    }

                }
            }
            // Then the the user is currently answering a short answer question type
            else if (allquestion[questnum].questiontype <=2 )
            {
                Boolean isValid = true;
                String selectedAnswer = Request["ShortQuestionAnswer"];
                // If its short answer numeric type only
                if (selectedAnswer == "")
                {
                    isValid = false;
                    String error = "webpollingError" + "," + "Please provide your answer(s)";
                    TempData["webpollingError"] = error;
                }
                else if (allquestion[questnum].questiontype == 1 && !Regex.IsMatch(selectedAnswer, @"^\d+$"))
                {
                    isValid = false;
                    String error = "webpollingError" + "," + "Only numeric answer is allowed";
                    Session["shortAnswer"] = "";
                    TempData["webpollingError"] = error;
                }
                else if (allquestion[questnum].questiontype == 2 && Regex.IsMatch(selectedAnswer, @"^\d+$"))
                {
                    isValid = false;
                    String error = "webpollingError" + "," + "Only alphanumeric answer is not allowed";
                    Session["shortAnswer"] = "";
                    TempData["webpollingError"] = error;
                }
                if (isValid)
                {
                    AnswerShortAnswerQuestion(selectedAnswer, sessionid, (int)Session["uid"], currentquestion);

                    List<questionModel> tempList = new questionModel().displayQuestionsFromAPoll(pollid);
                    if (button == "Previous Question")
                    {
                        Session["currentQuestionNumber"] = questnum - 1;
                        int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid;
                        setNextAnswer(questnum + 1, nextquestion, sessionid, (int)Session["uid"]);

                    }

                    // if its the last question, then submit/ update answer but stay on the same question
                    else if (button == "Submit Last Answer")
                    {
                        Session["currentQuestionNumber"] = questnum;
                        Session["shortAnswer"] = Request["ShortQuestionAnswer"];
                        Session["completed"] = "Thank you, you have completed all of the questions in this session.";
                    }
                    // its the next button
                    else
                    {
                        Session["currentQuestionNumber"] = questnum + 1;
                        int nextquestion = allquestion[(int)Session["currentQuestionNumber"]].questionid;
                        setNextAnswer(questnum - 1, nextquestion, sessionid, (int)Session["uid"]);
                    }
                }

            }

            return RedirectToAction("StartAsyncSession", new { sessionid = sessionid, pollid = pollid });
        }