예제 #1
0
        public ActionResult DeleteDetail()
        {
            Dictionary <string, dynamic> rs = new Dictionary <string, dynamic>()
            {
                { "msg", "การทำงานไม่ถูกต้อง" },
                { "msgType", AlertMsgType.Danger }
            };

            try
            {
                int id                 = Request.Form["id"].ParseInt();
                int TeamId             = Request.Form["TeamId"].ParseInt();
                TeamOperationDetail ob = uow.Modules.TeamOperationDetail.Get(id);
                if (ob == null)
                {
                    return(RedirectToAction("Detail", "TeamOperation", new { id = TeamId, msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning }));
                }

                uow.Modules.TeamOperationDetail.Delete(ob);
                uow.SaveChanges();
                return(RedirectToAction("Detail", "TeamOperation", new { id = TeamId, msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                int TeamId = Request.Form["TeamId"].ParseInt();
                return(RedirectToAction("Detail", "TeamOperation", new { id = TeamId, msg = ex.GetMessage(), msgType = AlertMsgType.Danger }));
            }
        }
예제 #2
0
        public static bool IsValid(this TeamOperationDetail ob, out string errorMsg)
        {
            errorMsg = string.Empty;
            if (ob == null)
            {
                errorMsg = "ไม่พบข้อมูล";
                return(false);
            }
            else
            {
                List <string> err = new List <string>();
                if (ob.TeamId <= 0)
                {
                    err.Add("ไม่สามารถระบุทีมได้, กรณาลองใหม่อีกครั้ง");
                }
                if (ob.AccountId <= 0)
                {
                    err.Add("กรุณากำหนดสมาชิก");
                }

                if (err.Count() > 0)
                {
                    errorMsg = "กรุณาตรวจสอบข้อมูลต่อไปนี้";
                    foreach (string s in err)
                    {
                        errorMsg += @"{\n}- " + s;
                    }
                    return(false);
                }
                return(true);
            }
        }
예제 #3
0
        public ActionResult SetDetail()
        {
            Dictionary <string, dynamic> rs = new Dictionary <string, dynamic>()
            {
                { "msg", "การทำงานไม่ถูกต้อง" },
                { "msgType", AlertMsgType.Danger }
            };
            int           teamId      = Request.Form["teamId"].ParseInt();
            string        teamSaleIds = Request.Form["hdApprove"];
            TeamOperation ob          = uow.Modules.TeamOperation.GetSingle(teamId);
            bool          isInsert    = ob.TeamId <= 0;

            if (ob.TeamId <= 0)
            {
                ob.CreatedBy   = CurrentUID;
                ob.CreatedDate = CurrentDate;
            }
            ob.TeamName    = Request.Form["teamName"];
            ob.ManagerId   = Request.Form["managerId"].ParseInt();
            ob.UpdatedBy   = CurrentUID;
            ob.UpdatedDate = CurrentDate;
            try
            {
                if (!ob.IsValid(out string errMsg))
                {
                    throw new Exception(errMsg);
                }

                uow.Modules.TeamOperation.Set(ob);
                uow.SaveChanges();

                List <TeamOperationDetail> obTeamDetail = uow.Modules.TeamOperationDetail.Gets(teamId);
                if (obTeamDetail != null && obTeamDetail.Count > 0 && teamSaleIds != "")
                {
                    foreach (string accountId in teamSaleIds.Split(','))
                    {
                        TeamOperationDetail detail = obTeamDetail.Find(o => o.AccountId == accountId.ParseLong());
                        detail.Approve = "1";

                        uow.Modules.TeamOperationDetail.Set(detail);
                    }

                    uow.SaveChanges();
                }
                rs["msg"]     = "บันทึกข้อมูลเรียบร้อยแล้ว";
                rs["msgType"] = AlertMsgType.Success;

                if (isInsert)
                {
                    rs.Add("id", ob.TeamId);
                }
                return(isInsert ? UrlRedirect(PathHelper.OperationTeamDetail, rs) : UrlRedirect(PathHelper.OperationTeam, rs));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage();
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
예제 #4
0
        public ActionResult SetDetailData()
        {
            Dictionary <string, dynamic> rs = new Dictionary <string, dynamic>()
            {
                { "msg", "การทำงานไม่ถูกต้อง" },
                { "msgType", AlertMsgType.Danger }
            };
            int id = Request.Form["id"].ParseInt();
            TeamOperationDetail ob = uow.Modules.TeamOperationDetail.Get(id);

            if (ob.Id <= 0)
            {
                ob.TeamId      = Request.Form["teamId"].ParseInt();
                ob.CreatedBy   = CurrentUID;
                ob.CreatedDate = CurrentDate;
            }
            ob.TeamRemark  = Request.Form["teamRemark"];
            ob.AccountId   = Request.Form["accountId"].ParseInt();
            ob.UpdatedBy   = CurrentUID;
            ob.UpdatedDate = CurrentDate;
            try
            {
                if (!ob.IsValid(out string errMsg))
                {
                    throw new Exception(errMsg);
                }

                uow.Modules.TeamOperationDetail.Set(ob);
                uow.SaveChanges();

                rs["msg"]     = "บันทึกข้อมูลเรียบร้อยแล้ว";
                rs["msgType"] = AlertMsgType.Success;
            }
            catch (Exception ex)
            {
                rs["msg"]     = ex.GetMessage();
                rs["msgType"] = AlertMsgType.Danger;
            }
            finally
            {
                rs.Add("id", ob.TeamId);
            }
            return(UrlRedirect(PathHelper.OperationTeamDetail, rs));
        }