public ActionResult NewProject()
        {
            string error = "";

            var dtl     = new DataTools();
            var header  = null as Models.DataModels.iteam_project;
            var detail  = null as List <Models.DataModels.iteam_project_user>;
            var history = null as List <Models.DataModels.iteam_history_project>;


            var tmp = new
            {
                header  = new Dictionary <string, object>(),
                detail  = new List <Dictionary <string, object> >(),
                history = new List <Dictionary <string, object> >(),
            };

            try
            {
                var json_string = dtl.JsonRequest();
                tmp     = JsonConvert.DeserializeAnonymousType(json_string, tmp);
                header  = dtl.DictionaryToModel(tmp?.header, new Models.DataModels.iteam_project()).FirstOrDefault() as Models.DataModels.iteam_project;
                detail  = dtl.DictionaryToModel(tmp?.detail, new Models.DataModels.iteam_project_user()).Select(x => x as Models.DataModels.iteam_project_user).ToList();
                history = dtl.DictionaryToModel(tmp?.history, new Models.DataModels.iteam_history_project()).Select(x => x as Models.DataModels.iteam_history_project).ToList();
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (string.IsNullOrEmpty(error))
            {
                new Models.Project.Project(auth).NewProject(header, detail, history, ref error);
            }

            var output = new
            {
                success = string.IsNullOrEmpty(error?.Trim()),
                error   = error?.Trim(),
                data    = new
                {
                    header,
                    detail,
                    history
                }
            };

            return(Content(JsonConvert.SerializeObject(output), "application/json"));
        }
        public ActionResult DeleteTaskList()
        {
            string error = "";

            var dtl = new DataTools();

            var m = null as Models.DataModels.iteam_task_lists;

            var tmp = new Dictionary <string, object>();

            try
            {
                var json_string = dtl.JsonRequest();
                tmp = JsonConvert.DeserializeAnonymousType(json_string, tmp);
                m   = dtl.DictionaryToModel(tmp, new Models.DataModels.iteam_task_lists()).FirstOrDefault() as Models.DataModels.iteam_task_lists;
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (string.IsNullOrEmpty(error))
            {
                new Models.Project.Project(auth).DeleteTaskList(m, ref error);
            }

            var output = new
            {
                success = string.IsNullOrEmpty(error?.Trim()),
                error   = error?.Trim(),
                data    = m
            };

            return(Content(JsonConvert.SerializeObject(output), "application/json"));
        }
        public ActionResult DeleteMemberGroup()
        {
            string error = "";

            var dtl = new DataTools();

            var detail = null as List <Models.DataModels.iteam_group_user>;

            var tmp = new
            {
                detail = new List <Dictionary <string, object> >(),
            };


            try
            {
                var json_string = dtl.JsonRequest();
                tmp    = JsonConvert.DeserializeAnonymousType(json_string, tmp);
                detail = dtl.DictionaryToModel(tmp?.detail, new Models.DataModels.iteam_group_user()).Select(x => x as Models.DataModels.iteam_group_user).ToList();
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (string.IsNullOrEmpty(error))
            {
                new Models.Member.MemberGroup(auth).DeleteMemberGroup(detail, ref error);
            }

            var output = new
            {
                success = string.IsNullOrEmpty(error?.Trim()),
                error   = error?.Trim(),
                data    = new
                {
                    detail
                }
            };

            return(Content(JsonConvert.SerializeObject(output), "application/json"));
        }
        public ActionResult ContactAdd()
        {
            string error = "";


            var dtl  = new DataTools();
            var data = null as Models.DataModels.iteam_contact;

            var tmp = new
            {
                data = new Dictionary <string, object>(),
            };

            try
            {
                var json_string = dtl.JsonRequest();
                tmp  = JsonConvert.DeserializeAnonymousType(json_string, tmp);
                data = dtl.DictionaryToModel(tmp?.data, new Models.DataModels.iteam_contact()).FirstOrDefault() as Models.DataModels.iteam_contact;
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (string.IsNullOrEmpty(error))
            {
                new Models.Contact.Contact(auth).ContactAdd(data, ref error);
            }

            var output = new
            {
                success = string.IsNullOrEmpty(error?.Trim()),
                error   = error?.Trim(),
                data    = new
                {
                    data,
                }
            };

            return(Content(JsonConvert.SerializeObject(output), "application/json"));
        }
        public ActionResult UpdateListTask()
        {
            string error = "";

            var dtl = new DataTools();

            var listArray = null as List <Models.DataModels.iteam_task_lists>;

            var tmp = new
            {
                listArray = new List <Dictionary <string, object> >()
            };

            try
            {
                var json_string = dtl.JsonRequest();
                tmp       = JsonConvert.DeserializeAnonymousType(json_string, tmp);
                listArray = dtl.DictionaryToModel(tmp?.listArray, new Models.DataModels.iteam_task_lists()).Select(x => x as Models.DataModels.iteam_task_lists).ToList();
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (string.IsNullOrEmpty(error))
            {
                new Models.Project.Project(auth).UpdateTasksList(listArray, ref error);
            }

            var output = new
            {
                success = string.IsNullOrEmpty(error?.Trim()),
                error   = error?.Trim(),
                data    = listArray
            };

            return(Content(JsonConvert.SerializeObject(output), "application/json"));
        }
        public ActionResult CreateNews(HttpPostedFileBase file, string form, Models.DataModels.iteam_upload_pic pic)
        {
            string error = "";

            using (var db = new DataContext())
            {
                db.ExecuteTransaction(() =>
                {
                    var dtl = new DataTools();
                    var m   = null as Models.DataModels.iteam_news;
                    var tmp = new Dictionary <string, object>();

                    try
                    {
                        var json_string = form;
                        tmp             = JsonConvert.DeserializeAnonymousType(json_string, tmp);
                        m = dtl.DictionaryToModel(tmp, new Models.DataModels.iteam_news()).FirstOrDefault() as Models.DataModels.iteam_news;
                    } catch (Exception ex)
                    {
                        error = ex.Message;
                    }

                    var news_name = m?.news_name;
                    var news_des  = m?.news_des;

                    if (string.IsNullOrEmpty(news_name) && string.IsNullOrEmpty(news_des))
                    {
                        throw new Exception("โปรดกรอกข้อความก่อนส่ง");
                    }

                    m.add_date = DateTime.Now;
                    m.add_user = auth.user_id;
                    m          = db.iteam_news.Add(m);
                    db.SaveChanges();

                    if (file != null)
                    {
                        string _FileName = Path.GetFileName(file.FileName);
                        var new_name     = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + "." + Path.GetExtension(file.FileName).Replace(".", "");
                        var path         = System.Configuration.ConfigurationManager.AppSettings["UploadPath"];

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        var path_true = path + "\\" + new_name;

                        var new_id    = m?.news_id;
                        pic.itemno    = (db.iteam_upload_pic.Where(x => x.news_id == new_id).Select(s => s.itemno).Max() ?? 0) + 1;
                        pic.path_file = path_true;
                        pic.file_name = _FileName;
                        pic.add_user  = auth.user_id;
                        pic.add_dt    = DateTime.Now;
                        pic.news_id   = new_id;
                        db.iteam_upload_pic.Add(pic);
                        db.SaveChanges();
                        file.SaveAs(path_true);
                    }
                }, ref error);
            }


            var output = new
            {
                success = string.IsNullOrEmpty(error?.Trim()),
                error   = error?.Trim(),
            };

            return(Content(JsonConvert.SerializeObject(output), "application/json"));
        }