コード例 #1
0
        public JsonResult AddHost(HostDetailModel newHostDetail)
        {
            var result = new JsonResponse();

            try
            {
                HostListModel hostList = getHostList();

                if (!HostAdmin.IsExistHostName(hostList.HostList, newHostDetail.HostName))
                {
                    int newHostId = hostList.MaxHostId + 1;

                    newHostDetail.HostID     = newHostId;
                    newHostDetail.SortNumber = hostList.HostList.Count;
                    hostList.HostList.Add(newHostDetail);
                    hostList.MaxHostId = newHostId;

                    if (HostAdmin.SetHostList(hostList, HostListFilePath))
                    {
                        Session[Constants.SESSION_HOST_SETTING] = hostList;
                        result.SetResult(true);
                        result.AddData("hostId", newHostId.ToString());
                        result.AddData("hostName", newHostDetail.HostName);
                    }
                    else
                    {
                        result.AddErrorInfo("errorMessage", "新規追加に失敗!");
                    }
                }
                else
                {
                    result.AddErrorInfo("errorMessage", "既に登録されているホスト名です!");
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
コード例 #2
0
        public JsonResult EditHost(HostDetailModel editHostDetail)
        {
            var result = new JsonResponse();

            try
            {
                var hostList = getHostList();

                var newHosts       = new HostListModel();
                var hostDetailList = new List <HostDetailModel>();

                bool isEdit = false;

                if (HostAdmin.GetHostName(hostList.HostList, editHostDetail.HostID) == editHostDetail.HostName)
                {
                    isEdit = true;
                }
                else if (!HostAdmin.IsExistHostName(hostList.HostList, editHostDetail.HostName))
                {
                    isEdit = true;
                }

                if (isEdit)
                {
                    foreach (HostDetailModel hostDetail in hostList.HostList)
                    {
                        if (hostDetail.HostID.Equals(editHostDetail.HostID))
                        {
                            hostDetailList.Add(editHostDetail);
                        }
                        else
                        {
                            hostDetailList.Add(hostDetail);
                        }
                    }
                    newHosts.HostList  = hostDetailList;
                    newHosts.MaxHostId = hostList.MaxHostId;

                    if (HostAdmin.SetHostList(newHosts, HostListFilePath))
                    {
                        Session[Constants.SESSION_HOST_SETTING] = newHosts;
                        result.SetResult(true);
                        result.AddData("hostId", editHostDetail.HostID.ToString());
                        result.AddData("hostName", editHostDetail.HostName);
                    }
                    else
                    {
                        result.AddErrorInfo("errorMessage", "ホスト設定の修正に失敗!");
                    }
                }
                else
                {
                    result.AddErrorInfo("errorMessage", "既に登録されているホスト名です!");
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
コード例 #3
0
        public JsonResult CopyHost(int selectHostId, string NewHostName)
        {
            var result = new JsonResponse();

            try
            {
                HostListModel hosts = getHostList();

                if (!HostAdmin.IsExistHostID(hosts.HostList, selectHostId))
                {
                    result.AddErrorInfo("errorMessage", "コピー元のホストが存在しません!");
                }
                else
                {
                    int    newHostId   = hosts.MaxHostId + 1;
                    string newHostName = string.Empty;

                    if (NewHostName == string.Empty || HostAdmin.IsExistHostName(hosts.HostList, NewHostName))
                    {
                        newHostName = "Untitled_" + newHostId;
                    }
                    else
                    {
                        newHostName = NewHostName;
                    }

                    foreach (HostDetailModel hostDetail in hosts.HostList)
                    {
                        if (hostDetail.HostID == selectHostId)
                        {
                            var newHostDetail = new HostDetailModel(hostDetail);
                            newHostDetail.HostName   = newHostName;
                            newHostDetail.HostID     = newHostId;
                            newHostDetail.SortNumber = hosts.HostList.Count;
                            hosts.HostList.Add(newHostDetail);
                            hosts.MaxHostId = newHostId;

                            break;
                        }
                    }

                    if (HostAdmin.SetHostList(hosts, HostListFilePath))
                    {
                        Session[Constants.SESSION_HOST_SETTING] = hosts;
                        result.SetResult(true);
                        result.AddData("hostId", newHostId.ToString());
                        result.AddData("hostName", newHostName);
                    }
                    else
                    {
                        result.AddErrorInfo("errorMessage", "新規追加に失敗!");
                    }
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }