public ActionResult EDITEvent(string Name, string Event_Code, DateTime Start_Date, DateTime End_Date, int ID, string Password) { using (ProjectJobEntities db = new ProjectJobEntities()) { Eit bussiness = new Eit(); bool IsDupicate = bussiness.CheckEdit(Event_Code, Start_Date, End_Date, ID); if (!IsDupicate) { var EditView = db.Event.Where(x => x.Event_ID == ID).SingleOrDefault(); EditView.Event_Code = Event_Code; EditView.Start_Date = Start_Date; EditView.End_Date = End_Date; EditView.Event_Name = Name; EditView.Event_Password = Password; db.SaveChanges(); var alerte = new { Result = "กิจกรรมได้รับการอัพเดต" }; return(Json(alerte)); } else { // TempData["msg"] = "<script>alert('Your Timeline is already Exist.');</script>"; var alerte = new { Result = "ช่วงระเวลากิจกรรมของคุณเกิดความซ้ำซ้อน" }; return(Json(alerte)); } } }
public ActionResult UpdateNtf(int id, string status) { var eid = Convert.ToInt32(Session["Event_ID"]); var ID = Convert.ToInt32(id); var Status = Convert.ToBoolean(status); using (ProjectJobEntities db = new ProjectJobEntities()) { var call = db.Polls.Where(x => x.Event_ID == eid).ToList(); foreach (var poo in call) { poo.IsActive = false; } var result = db.Polls.Where(a => a.Polls_ID == ID).SingleOrDefault(); if (result != null) { result.IsActive = Status; } db.SaveChanges(); var results = new { ID = result.Polls_ID, TID = result.Polls_Type_ID }; return(Json(results)); } }
public ActionResult CrateUser(string FirstName, string LastName, string password, string Email, string ConfirmPassword) { if (FirstName == "") { var results = new { Result = "กรุณากรอกข้อมูลทั้งหมด", Poll = "" }; return(Json(results)); } if (LastName == "") { var results = new { Result = "กรุณากรอกข้อมูลทั้งหมด", Poll = "" }; return(Json(results)); } if (Email == "") { var results = new { Result = "กรุณากรอกข้อมูลทั้งหมด", Poll = "" }; return(Json(results)); } if (password != ConfirmPassword) { var results = new { Result = "รหัสผ่านของคุณทั้งสองช่องไม่เหมือนกัน", Poll = "" }; return(Json(results)); } using (ProjectJobEntities db = new ProjectJobEntities()) { if (db.Users.Any(x => x.Email == Email)) { var results = new { Result = "อีเมลของคุณถูกใช้แล้ว", Poll = "" }; return(Json(results)); } password = PasswordStorage.CreateHash(password); var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); var RandomID = new string(Enumerable.Repeat(chars, 13).Select(s => s[random.Next(s.Length)]).ToArray()); db.Users.Add(new Users() { FirstName = FirstName, LastName = LastName, Password = password, Email = Email, Ses_ID = RandomID }); db.SaveChanges(); } ModelState.Clear(); var result = new { Result = "การสมัครสมาชิกสำเร็จ", Poll = 1 }; return(Json(result)); }
public ActionResult UpdateUser(string FirstName, string LastName, int User_ID) { using (ProjectJobEntities db = new ProjectJobEntities()) { var UpdateUser = db.Users.Where(x => x.User_ID == User_ID).SingleOrDefault(); UpdateUser.FirstName = FirstName; UpdateUser.LastName = LastName; db.SaveChanges(); return(Json(JsonRequestBehavior.AllowGet)); } }
public ActionResult DeletEvent(int EventID) { using (ProjectJobEntities db = new ProjectJobEntities()) { Event EventDetail = db.Event.Find(EventID); db.Event.Remove(EventDetail); db.SaveChanges(); var alerte = new { Result = "ลบเสร็จสิ้น" }; return(Json(alerte)); } }
public ActionResult DeletPoll(int PollID) { using (ProjectJobEntities db = new ProjectJobEntities()) { Polls pollDetail = db.Polls.Find(PollID); db.Polls.Remove(pollDetail); db.SaveChanges(); var alertt = "ลบเสร็จสิ้น"; return(Json(alertt)); } }
public ActionResult AddAnswer(int PollTypes, int PollID, string Options, int Rate, string Text, int MaxMulti) { if (Text == "") { Text = null; } if (PollTypes == 1 && Options == "0") { var result = new { Result = " การเพิ่มคำตอบไม่สำเร็จ", Check = 0 }; return(Json(result)); } if (PollTypes == 4 && Rate == 0) { var result = new { Result = " การเพิ่มคำตอบไม่สำเร็จ", Check = 0 }; return(Json(result)); } if (PollTypes == 2 && Text == null) { var result = new { Result = " การเพิ่มคำตอบไม่สำเร็จ", Check = 0 }; return(Json(result)); } if (PollTypes == 3 && Text == null) { var result = new { Result = " การเพิ่มคำตอบไม่สำเร็จ", Check = 0 }; return(Json(result)); } if (PollTypes == 1) { string[] OPtsr = Options.Trim().Split(' '); int CheckMax = OPtsr.Length; if (CheckMax > MaxMulti) { var result = new { Result = "กรุณาเลือกตัวเลือกแค่ " + MaxMulti + " ตัวเลือก", Check = 0 }; return(Json(result)); } } if (PollTypes == 3 && Text != null) { Text = Text.ToLower(); } using (ProjectJobEntities db = new ProjectJobEntities()) { CPC bussiness = new CPC(); bool IsDupicate = bussiness.CheckPollClose(PollID); if (IsDupicate) { Outer Pmodel = new Outer() { Polls_ID = PollID, Outer_Text = Text, Outer_Rating = Rate, Outer_Name = Convert.ToString(Session["FirstName"]), OuterSes_ID = Convert.ToString(Session["Ses_ID"]) }; db.Outer.Add(Pmodel); if (PollTypes == 1) { string[] OPtsr = Options.Trim().Split(' '); foreach (var poo in OPtsr) { int Op = Convert.ToInt32(poo); OuterOptions Omodel = new OuterOptions() { Outer_ID = Pmodel.Outer_ID, Options_ID = Op }; db.OuterOptions.Add(Omodel); } } db.SaveChanges(); var result = new { Result = " การเพิ่มคำตอบสำเร็จ", id = Pmodel.Polls_ID, type = PollTypes, Check = 1 }; return(Json(result)); } else { var result = new { Result = " กิจกรรมนี้ปิดไปแล้ว, กรุณาหากิจกรรมอื่น", Check = 2 }; return(Json(result)); } } }
public ActionResult EDITEPoll(string Name, int rating, int ID, int Type, string ID_Options, string Options, int NumMulti, string Ismulti, int Limit) { using (ProjectJobEntities db = new ProjectJobEntities()) { var EditPollView = db.Polls.Where(x => x.Polls_ID == ID).SingleOrDefault(); EditPollView.Polls_Name = Name; EditPollView.LimitPerson = Limit; if (Type == 4) { if (EditPollView.Rating != rating) { var SurveyRate = db.Outer.Where(x => x.Polls_ID == ID && x.Outer_Rating > rating).ToArray(); for (int i = 0; i < SurveyRate.Length; i++) { db.Outer.Remove(SurveyRate[i]); } EditPollView.Rating = rating; } } if (Type == 1) { string[] CheckID_Options = ID_Options.Trim().Split('|'); string[] CheckOptions = Options.Trim().Split('|'); var IDLength = CheckID_Options.Length; Dictionary <string, string> Repeatedoptions = new Dictionary <string, string>(); for (int i = 0; i < IDLength; i++) { if (CheckOptions[i] != "") { if (Repeatedoptions.ContainsKey(CheckOptions[i])) // Check if word already exist in dictionary update the count { var alertes = new { Result = "กรุณาตรวจสอบตัวเลือกของคุณ เนื่องจากเกิดความซ้ำซ้อน", Get = 1 }; return(Json(alertes)); } else { Repeatedoptions.Add(CheckOptions[i], CheckID_Options[i]); } } } Dictionary <string, int> GetOldoptions = new Dictionary <string, int>(); for (int i = 0; i < IDLength; i++) { if (CheckOptions[i] != "") { var toint = Convert.ToInt32(CheckID_Options[i]); if (toint != 0) // Check if word already exist in dictionary update the count { GetOldoptions.Add(CheckOptions[i], toint); } } } Dictionary <string, int> Newoptions = new Dictionary <string, int>(); for (int i = 0; i < IDLength; i++) { if (CheckOptions[i] != "") { var toint = Convert.ToInt32(CheckID_Options[i]); if (toint == 0) // Check if word already exist in dictionary update the count { Newoptions.Add(CheckOptions[i], toint); } } } var OptionsLength = GetOldoptions.Count(); var OldOption = db.Options.Where(x => x.Polls_ID == ID).Select(x => x.Options_ID).ToArray(); var OldDataLength = OldOption.Length; if (OptionsLength == OldDataLength) { var checkBack = db.Options.Where(x => x.Polls_ID == ID); for (int index = 0; index < OptionsLength; index++) { var element = GetOldoptions.ElementAt(index); var key = element.Key; if (!checkBack.Any(x => x.Options_Name == key)) { var OptionID = Convert.ToInt32(element.Value); var UpdateBack = db.Options.Where(x => x.Polls_ID == ID && x.Options_ID == OptionID).SingleOrDefault(); { UpdateBack.Options_Name = key; }; } } } if (OptionsLength < OldDataLength) { int[] checkBack = db.Options.Where(x => x.Polls_ID == ID).Select(x => x.Options_ID).ToArray(); var OldStringID = ""; for (int iz = 0; iz < checkBack.Length; iz++) { var a = Convert.ToString(checkBack[iz]); OldStringID = OldStringID + " " + a; } string[] OldStringID_Split = OldStringID.Trim().Split(' '); var OldStringID_Length = OldStringID_Split.Length; for (int index = 0; index < OldStringID_Length; index++) { var intOldID = Convert.ToInt32(OldStringID_Split[index]); if (!GetOldoptions.Any(x => x.Value == intOldID)) { Options OptionDelete = db.Options.Find(intOldID); db.Options.Remove(OptionDelete); } } } if (Newoptions.Count != 0) { foreach (var kvp in Newoptions) { if (kvp.Key != "") { Options Omodel = new Options() { Polls_ID = ID, Options_Name = kvp.Key }; db.Options.Add(Omodel); } } } var IsAllowMulti = Convert.ToBoolean(Ismulti); var UpdateBack2 = db.Polls.Where(x => x.Polls_ID == ID).SingleOrDefault(); { UpdateBack2.IsMulti = IsAllowMulti; UpdateBack2.MaxMulti = NumMulti; }; } db.SaveChanges(); var signalID = db.Polls.Where(x => x.Polls_ID == ID).Select(x => x.Polls_ID).SingleOrDefault(); var signalType = db.Polls.Where(x => x.Polls_ID == ID).Select(x => x.Polls_Type_ID).SingleOrDefault(); var Signal = new { signalID, signalType }; var alerte = new { Result = "โพลคำถามอัพเดตแล้ว", Get = 0, s = Signal }; return(Json(alerte)); } }
public ActionResult Create(Event eventmodel) { if (eventmodel.Event_Name == null) { var result = new { Result = " เกิดความผิดในการกรอกข้อมูลของคุณ", Event = "" }; return(Json(result)); } if (eventmodel.Event_Code == null) { var result = new { Result = " เกิดความผิดในการกรอกข้อมูลของคุณ", Event = "" }; return(Json(result)); } DateTime date = Convert.ToDateTime(@"01/01/01"); if (eventmodel.Start_Date == date) { var result = new { Result = " เกิดความผิดในการกรอกข้อมูลของคุณ", Event = "" }; return(Json(result)); } string today = DateTime.Now.AddYears(-543).AddDays(1).ToString("dd/MM/yy"); DateTime today1 = Convert.ToDateTime(today); if (eventmodel.Start_Date == today1) { var result = new { Result = " เกิดความผิดในการกรอกข้อมูลของคุณ กรุณาอย่าตั้งเวลาน้อยกว่าเวลาปัจจุบัน", Event = "" }; return(Json(result)); } if (eventmodel.End_Date == date) { var result = new { Result = " เกิดความผิดในการกรอกข้อมูลของคุณ", Event = "" }; return(Json(result)); } string TestEventPass = eventmodel.Event_Password; if (TestEventPass != null) { if (TestEventPass.Equals("ErrorCaseWhiteSpace")) { var result = new { Result = " กรุณาใส่รหัสผ่านหรือลบเครื่องหมายหากคุณไม่ต้องการใส่รหัสผ่าน", Event = "" }; return(Json(result)); } } var CodeUpperCase = eventmodel.Event_Code.ToUpper(); CheckDupe bussiness = new CheckDupe(); bool IsDupicate = bussiness.CheckDupicate(CodeUpperCase, eventmodel.Start_Date, eventmodel.End_Date); if (!IsDupicate) { using (ProjectJobEntities db = new ProjectJobEntities()) { Event model = new Event() { Event_Code = CodeUpperCase, Event_Name = eventmodel.Event_Name, Start_Date = eventmodel.Start_Date, End_Date = eventmodel.End_Date, Users_ID = Convert.ToInt32(Session["User_ID"]), Event_Password = eventmodel.Event_Password }; db.Event.Add(model); db.SaveChanges(); var result = new { Result = "บันทึกกิจกรรมสำเร็จ", Event = model }; return(Json(result)); } } else { // TempData["msg"] = "<script>alert('Your Timeline is already Exist.');</script>"; var result = new { Result = " ช่วงเวลาของคุณซ้ำ กรุณาเปลี่ยนช่วงเวลา หรือ รหัสกิจกรรม", Event = "" }; return(Json(result)); } }
public ActionResult AddPoll(int PollTypes, string PollName, string OPts, int Ratng, int NumMulti, string Ismulti, int Limit) { if (PollName != "") { if (PollTypes == 1) { string[] OPtsrCheck = OPts.Trim().Split('|'); var numOPcheck = OPtsrCheck.Length; if (OPtsrCheck[0] == "") { var i = 0; foreach (var poo in OPtsrCheck) { if (String.IsNullOrWhiteSpace(poo) || poo == "") { i = 1 + i; } } if (numOPcheck == i) { var results = new { Result = " กรุณาเพิ่มตัวเลือกของคุณ", Poll = "" }; return(Json(results)); } } else { if (String.IsNullOrWhiteSpace(OPtsrCheck[0])) { var results = new { Result = " กรุณาเพิ่มตัวเลือกของคุณ", Poll = "" }; return(Json(results)); } } Dictionary <string, int> checkRepeatWord = new Dictionary <string, int>(); for (int i = 0; i < numOPcheck; i++) //loop the splited string { if (OPtsrCheck[i] != "") { if (checkRepeatWord.ContainsKey(OPtsrCheck[i])) // Check if word already exist in dictionary update the count { var results = new { Result = " กรุณาตรวจสอบตัวเลือกของคุณ, บางตัวเลือกซ้ำกับตัวเลือกอื่น", Poll = "" }; return(Json(results)); } else { checkRepeatWord.Add(OPtsrCheck[i], 1); // if a string is repeated and not added in dictionary , here we are adding } } } } var IsAllowMulti = Convert.ToBoolean(Ismulti); using (ProjectJobEntities db = new ProjectJobEntities()) { Polls Pmodel = new Polls() { Polls_Name = PollName, Polls_Type_ID = PollTypes, Event_ID = Convert.ToInt32(Session["Event_ID"]), IsActive = false, Rating = Ratng, IsMulti = IsAllowMulti, MaxMulti = NumMulti, LimitPerson = Limit }; db.Polls.Add(Pmodel); if (PollTypes == 1) { string[] OPtsr = OPts.Trim().Split('|'); foreach (var poo in OPtsr) { if (poo != "") { Options Omodel = new Options() { Polls_ID = Pmodel.Polls_ID, Options_Name = poo }; db.Options.Add(Omodel); } } } db.SaveChanges(); var ViewPT = from po in db.Polls join pot in db.Polls_Type on po.Polls_Type_ID equals pot.Polls_Type_ID where po.Polls_ID == Pmodel.Polls_ID select new SelectPolltype { Polls_ID = po.Polls_ID, Polls_Name = po.Polls_Name, Polls_Type_ID = pot.Polls_Type_ID, Polls_Type_Name = pot.Polls_Type_Name, Type_Color = pot.Type_Color, Type_icon = pot.Type_icon, IsActive = po.IsActive }; var view = ViewPT.ToList(); var result = new { Result = " บันทึกโพลคำถามสำเร็จ", Poll = 1, Create = view }; return(Json(result)); } } else { var result = new { Result = " กรุณากรอกชื่อของคำถาม", Poll = "" }; return(Json(result)); } }