public ActionResult Update()
        {
            if (!Request.IsAjaxRequest())
            {
                return(new EmptyResult());
            }

            // 新規の場合、0
            var id = V.ParseInt(Request.Form["ID"]) ?? 0;


            var err = Validate();

            if (err.Any())
            {
                return(Json(new { err = err }));
            }


            using (HMPZDDB db = new HMPZDDB())
            {
                Accuracy data = null;
                if (id == 0)
                {
                    data = new Accuracy();
                    // TODO これはバグってるな。。。
                    data.Created = data.Updated = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                    // TODO ログインユーザ
                    data.CreatedBy = data.UpdatedBy = DateTime.Now;
                }
                else
                {
                    data = db.Accuracy.Where(d => d.DeleteFlg != 1 && d.ID == id).FirstOrDefault();

                    // TODO これはバグってるな。。。
                    data.Updated = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                    // TODO ログインユーザ
                    data.UpdatedBy = DateTime.Now;
                }


                data.Order = V.ParseInt(Request.Form["Order"]) ?? 0;
                // data.Status

                if (id == 0)
                {
                    db.Accuracy.Add(data);
                    id = data.ID;
                }

                db.SaveChanges();
            }

            return(Json(new { res = "ok", id = id }));
        }
Beispiel #2
0
        /// <summary>
        /// 値のチェック
        /// </summary>
        /// <returns></returns>
        private String[] Validate()
        {
            var err = new List <String>();

            var id = V.ParseInt(Request.Form["ID"]) ?? 0;

            if ((V.ParseInt(Request.Form["TeamID"]) ?? 0) == 0)
            {
                err.Add("チームを選択してください");
            }

            // 空
            if (!(Request.Form["UserID"] ?? "").Split(',').Any())
            {
                err.Add("ユーザを選択してください");
            }

            return(err.ToArray());
        }
        /// <summary>
        /// 値のチェック
        /// </summary>
        /// <returns></returns>
        private String[] Validate()
        {
            var err = new List <String>();

            var id = V.ParseInt(Request.Form["ID"]) ?? 0;


            if ((V.ParseInt(Request.Form["Order"]) ?? 0) == 0)
            {
                err.Add("表示順を入力してください");
            }

            if (string.IsNullOrWhiteSpace(Request.Form["AccuracyName"]))
            {
                err.Add("ステータスを入力してください");
            }

            return(err.ToArray());
        }
Beispiel #4
0
        public ActionResult Update()
        {
            if (!Request.IsAjaxRequest())
            {
                return(new EmptyResult());
            }

            // 新規の場合、0
            var id = V.ParseInt(Request.Form["ID"]) ?? 0;


            var err = Validate();

            if (err.Any())
            {
                return(Json(new { err = err }));
            }


            using (HMPZDDB db = new HMPZDDB())
            {
                // チーム情報
                var teamId = V.ParseInt(Request.Form["TeamID"]) ?? 0;

                // 組織情報
                Teams         team         = null;
                Organizations organization = null;
                if (teamId > 0)
                {
                    team = db.Teams.Where(d => d.DeleteFlg != 1 && d.ID == teamId).FirstOrDefault();
                }
                if (team != null && !string.IsNullOrWhiteSpace(team.OrganizationID))
                {
                    organization = db.Organizations.Where(d => d.DeleteFlg != 1 && d.ID == team.OrganizationID).FirstOrDefault();
                }

                // ユーザ情報
                var userIdList = (Request.Form["UserIDList"] ?? "").Split(',');
                foreach (var row in userIdList)
                {
                    // 既存のユーザID x TeamID 情報は一度消す
                    var teamRepresentative = db.TeamRepresentatives.Where(d => d.DeleteFlg != 1 && d.TeamID == teamId && d.UserID == row).FirstOrDefault();
                    if (teamRepresentative != null)
                    {
                        db.TeamRepresentatives.Remove(teamRepresentative);
                    }

                    // 新規として追加
                    TeamRepresentatives data = new TeamRepresentatives();

                    data.Created = data.Updated = DateTime.Now;

                    // TODO ログインユーザ
                    data.CreatedBy = data.UpdatedBy = "";

                    // チーム情報
                    data.TeamID = teamId;

                    // 組織情報
                    if (organization != null)
                    {
                        data.CompanyName       = organization.CompanyName ?? "";
                        data.DivisionGroupName = organization.DivisionGroupCommonName;
                        data.DivisionName      = organization.DivisionAbbrName;
                        data.DepartmentName    = organization.DepartmentAbbrName;
                    }

                    Users user = db.Users.Where(d => d.DeleteFlg != 1 && d.ID == row).FirstOrDefault();
                    if (user == null)
                    {
                        continue;
                    }

                    data.UserID    = user.ID;
                    data.FirstName = user.FirstName;
                    data.LastName  = user.LastName;

                    db.TeamRepresentatives.Add(data);
                }


                db.SaveChanges();
            }

            return(Json(new { res = "ok" }));
        }