Beispiel #1
0
        public void updateUrl(string fullUrl, int engageid)
        {
            var engagementUrl = db.TB_Url.Where(x => x.engagepersonal_ID == engageid).FirstOrDefault();

            if (engagementUrl != null)
            {
                engagementUrl.url             = fullUrl;
                db.Entry(engagementUrl).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Beispiel #2
0
        public ActionResult SaveAllDataText(string[] values)
        {
            EngagementContext db = new EngagementContext();

            try
            {
                TB_Answer      ans              = new TB_Answer();
                TB_Answer_Text ansText          = new TB_Answer_Text();
                int            latestRecord     = 0;
                int            latestRecordText = 0;
                int            questionId       = Convert.ToInt32(values[5]);
                int            SaveSection      = Convert.ToInt32(values[6]);
                latestRecord     = GetLastRecord(1);
                latestRecordText = GetLastRecord(2);
                var      userDt = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");  // return 08/05/2016 12:56 PM
                DateTime oDate  = DateTime.ParseExact(userDt, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                if (Convert.ToInt32(values[7]) != 0)
                {
                    var UID   = int.Parse((values[0]));
                    var SecID = int.Parse((values[6]));
                    for (int i = 0; i < 3; i++, questionId++)
                    {
                        var ds = (from c in db.TB_Answer where c.engagepersonal_ID == UID && c.Section == SecID && c.Question_ID == questionId select c).ToList();
                        if (ds.Count > 0)
                        {
                            foreach (var item in ds)
                            {
                                item.AnswerResult = Convert.ToInt32(values[i + 2]);
                                item.dtStamp      = oDate;
                            }
                        }
                        db.SaveChanges();
                    }
                    //ไปอัพเดทข้อมูลในตาราง text comment
                    var qtest = int.Parse((values[5]));

                    var dtext = (from c in db.TB_Answer_Text where c.engagepersonal_ID == UID && c.Section == SecID && c.Question_ID == qtest select c).ToList();
                    if (dtext.Count > 0)
                    {
                        foreach (var item in dtext)
                        {
                            item.AnswerResult = (values[1]);
                            item.Section      = SaveSection;
                            item.dtStamp      = oDate;
                        }
                    }
                    db.SaveChanges();

                    if (questionId == 51)
                    {
                        Int32 engagementid   = Convert.ToInt32(values[0]);
                        var   engagementData = db.TB_Email.Where(x => x.engagepersonal_ID == engagementid).FirstOrDefault();
                        if (engagementData != null)
                        {
                            engagementData.StatusAccept    = 1;
                            engagementData.Survey_Commit   = oDate;
                            db.Entry(engagementData).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 3; i++, questionId++)//วนใส่ทีละ 3 ข้อ
                    {
                        if (latestRecord == 0)
                        {
                            latestRecord = 1;
                        }
                        else
                        {
                            latestRecord = latestRecord + 1;
                        }


                        ans.Question_ID       = questionId;   //คำถามข้อที่
                        ans.engagepersonal_ID = Convert.ToInt32(values[0]);
                        ans.AnswerEngage_ID   = latestRecord; //ตัวเลขที่มันรันไปเรื่อยๆๆด้วยมือเรา
                        ans.AnswerResult      = Convert.ToInt32(values[i + 2]);
                        ans.Section           = SaveSection;
                        ans.dtStamp           = oDate;
                        db.TB_Answer.Add(ans);
                        db.SaveChanges();
                    }
                    var      qtest  = int.Parse((values[5]));
                    DateTime oDateT = DateTime.ParseExact(userDt, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                    ansText.Question_ID       = qtest;            //คำถามข้อที่
                    ansText.engagepersonal_ID = Convert.ToInt32(values[0]);
                    ansText.AnswerEngage_ID   = latestRecordText; //ตัวเลขที่มันรันไปเรื่อยๆๆด้วยมือเรา
                    ansText.AnswerResult      = values[1];
                    ansText.Section           = SaveSection;
                    ansText.dtStamp           = oDateT;
                    db.TB_Answer_Text.Add(ansText);
                    db.SaveChanges();
                    if (questionId == 51)
                    {
                        Int32 engagementid   = Convert.ToInt32(values[0]);
                        var   engagementData = db.TB_Email.Where(x => x.engagepersonal_ID == engagementid).FirstOrDefault();
                        if (engagementData != null)
                        {
                            engagementData.StatusAccept    = 1;
                            engagementData.Survey_Commit   = oDateT;
                            db.Entry(engagementData).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }



                return(Redirect(Request.UrlReferrer.ToString()));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }