Beispiel #1
0
        public Answer Retrived(int id)
        {
            try
            {
                Answer           oA = new Answer();
                SBH_TR_QUESTIONS oB = _ctx.SBH_TR_QUESTIONS.Where(x => x.ROW_STATUS == fn.fg.IsActive && x.ID == id).FirstOrDefault();
                if (oB != null)
                {
                    oA.ID_QUESTIONS    = id;
                    oA.QUESTIONS       = oB.QUESTIONS;
                    oA.TITLE_QUESTIONS = oB.TITLE_QUESTIONS;

                    return(oA);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);

                throw new Exception(ex.Message);
            }
        }
Beispiel #2
0
        public Questions Retrived(int id)
        {
            try
            {
                Questions        oA = new Questions();
                SBH_TR_QUESTIONS oB = _ctx.SBH_TR_QUESTIONS.Where(x => x.ID == id && x.ROW_STATUS == fn.fg.IsActive).FirstOrDefault();
                if (oB != null)
                {
                    oA.ID          = oB.ID;
                    oA.ID_CATEGORY = oB.ID_CATEGORY;
                    //oA.ID_USER = oB.ID_USER;
                    oA.QUESTIONS = oB.QUESTIONS;
                    //oA.CREATED_TIME = oB.CREATED_TIME;
                    //oA.CREATED_BY = oB.CREATED_BY;
                    //oA.LAST_MODIFIED_TIME = oB.LAST_MODIFIED_TIME;
                    //oA.LAST_MODIFIED_BY = oB.LAST_MODIFIED_BY;
                    //oA.ROW_STATUS = oB.ROW_STATUS;

                    return(oA);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);

                throw new Exception(ex.Message);
            }
        }
Beispiel #3
0
        public bool Edit(int id, Questions par)
        {
            bool res = false;

            try
            {
                SBH_TR_QUESTIONS a = _ctx.SBH_TR_QUESTIONS.Find(id);
                if (a != null)
                {
                    a.ID_CATEGORY = par.ID_CATEGORY;
                    //a.ID_USER = par.ID_USER;
                    a.QUESTIONS          = par.QUESTIONS;
                    a.CREATED_BY         = null;
                    a.LAST_MODIFIED_TIME = DateTime.Now;
                    a.LAST_MODIFIED_BY   = "System";

                    _ctx.Entry(a).State = System.Data.Entity.EntityState.Modified;
                    _ctx.SaveChanges();

                    res = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(res);
        }
Beispiel #4
0
        public object[] Add(Questions par)
        {
            object[] res;
            string   flag = "0";

            try
            {
                int maxid = 0;
                try
                {
                    SBH_TR_QUESTIONS o = _ctx.SBH_TR_QUESTIONS.OrderByDescending(s => s.ID).First();
                    maxid = o.ID + 1;
                }
                catch { maxid = maxid + 1; }


                SBH_TR_QUESTIONS a = new SBH_TR_QUESTIONS()
                {
                    ID_CATEGORY     = par.ID_CATEGORY,
                    ID_USER         = par.ID_USER,
                    QUESTIONS       = par.QUESTIONS,
                    CREATED_TIME    = DateTime.Now,
                    CREATED_BY      = par.USER_NAME,
                    ROW_STATUS      = fn.fg.IsActive,
                    MOST_COMMENT    = 0,
                    TITLE_QUESTIONS = par.TITLE_QUESTIONS,
                    MAXID           = maxid
                };
                _ctx.SBH_TR_QUESTIONS.Add(a);
                _ctx.SaveChanges();

                SBH_TM_USER_ADMIN b = _ctx.SBH_TM_USER_ADMIN.Find(par.ID_USER);
                if (b != null)
                {
                    int x = 0;
                    if (!String.IsNullOrWhiteSpace(b.MOST_ACT_QUESTIONS.ToString()))
                    {
                        x = int.Parse(b.MOST_ACT_QUESTIONS.ToString());
                    }

                    b.MOST_ACT_QUESTIONS      = x + 1;
                    b.MOST_ACT_QUESTIONS_DATE = DateTime.Now;

                    _ctx.Entry(b).State = System.Data.Entity.EntityState.Modified;
                    _ctx.SaveChanges();
                }

                flag = "1";
                res  = new object[] { flag, maxid };
            }
            catch (Exception ex)
            {
                res = new object[] { flag, "" };
                throw new Exception(ex.Message);
            }
            return(res);
        }
Beispiel #5
0
        public bool Delete(int id)
        {
            bool res = false;

            try
            {
                SBH_TR_QUESTIONS a = _ctx.SBH_TR_QUESTIONS.Find(id);
                a.ROW_STATUS        = fn.fg.NotActive;
                _ctx.Entry(a).State = System.Data.Entity.EntityState.Modified;
                res = true;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(res);
        }
Beispiel #6
0
        public bool Add(Answer ans)
        {
            bool res = false;

            try
            {
                SBH_TR_ANSWER a = new SBH_TR_ANSWER()
                {
                    ID_QUESTIONS  = ans.ID_QUESTIONS,
                    ID_USER_ADMIN = ans.ID_USER_ADMIN,
                    ANSWER        = ans.ANSWER,
                    CREATED_TIME  = DateTime.Now,
                    CREATED_BY    = ans.CREATED_BY,
                    ROW_STATUS    = fn.fg.IsActive
                };
                _ctx.SBH_TR_ANSWER.Add(a);
                _ctx.SaveChanges();

                SBH_TR_QUESTIONS b = _ctx.SBH_TR_QUESTIONS.Find(ans.ID_QUESTIONS);
                if (b != null)
                {
                    b.MOST_COMMENT_DATE = DateTime.Now;
                    b.MOST_COMMENT      = b.MOST_COMMENT + 1;

                    _ctx.Entry(b).State = System.Data.Entity.EntityState.Modified;
                    _ctx.SaveChanges();
                }

                //Answer from Guest doesn't record
                if (ans.ID_USER_ADMIN != 9)
                {
                    SBH_TM_USER_ADMIN c = _ctx.SBH_TM_USER_ADMIN.Find(ans.ID_USER_ADMIN);
                    if (c != null)
                    {
                        int x = 0;
                        if (!String.IsNullOrWhiteSpace(c.MOST_ACT_ANSWER.ToString()))
                        {
                            x = int.Parse(c.MOST_ACT_ANSWER.ToString());
                        }

                        c.MOST_ACT_ANSWER      = x + 1;
                        c.MOST_ACT_ANSWER_DATE = DateTime.Now;

                        _ctx.Entry(c).State = System.Data.Entity.EntityState.Modified;
                        _ctx.SaveChanges();
                    }
                }

                SBH_TR_QUESTIONS_TAGGING d = _ctx.SBH_TR_QUESTIONS_TAGGING.Where(x => x.ID_QUESTIONS == ans.ID_QUESTIONS && x.ID_USER_TAGGING == ans.ID_USER_ADMIN).FirstOrDefault();
                if (d != null)
                {
                    d.ANSWER_STATUS      = fn.fg.IsActive;
                    d.LAST_MODIFIED_TIME = DateTime.Now;
                    d.LAST_MODIFIED_BY   = ans.CREATED_BY;
                    _ctx.Entry(d).State  = System.Data.Entity.EntityState.Modified;
                    _ctx.SaveChanges();
                }
                res = true;
            }
            catch (Exception ex)
            {
                res = false;
            }
            return(res);
        }