Beispiel #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();
                TeamSaleDetail ob     = uow.Modules.TeamSaleDetail.Get(id);
                if (ob == null)
                {
                    return(RedirectToAction("Detail", "TeamAccount", new { id = TeamId, msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning }));
                }

                uow.Modules.TeamSaleDetail.Delete(ob);
                uow.SaveChanges();
                return(RedirectToAction("Detail", "TeamAccount", new { id = TeamId, msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            {
                int TeamId = Request.Form["TeamId"].ParseInt();
                return(RedirectToAction("Detail", "TeamAccount", new { id = TeamId, msg = ex.GetMessage(), msgType = AlertMsgType.Danger }));
            }
        }
        public static bool IsValid(this TeamSaleDetail 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);
            }
        }
Beispiel #3
0
        public ActionResult SetDetailData()
        {
            Dictionary <string, dynamic> rs = new Dictionary <string, dynamic>()
            {
                { "msg", "การทำงานไม่ถูกต้อง" },
                { "msgType", AlertMsgType.Danger }
            };
            int            id = Request.Form["id"].ParseInt();
            TeamSaleDetail ob = uow.Modules.TeamSaleDetail.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.TeamSaleDetail.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.AccountTeamDetail, rs));
        }
Beispiel #4
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"];
            TeamSale ob          = uow.Modules.TeamSale.Get(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;
            ob.DepartmentId = departmentID;
            try
            {
                if (!ob.IsValid(out string errMsg))
                {
                    throw new Exception(errMsg);
                }

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

                List <TeamSaleDetail> obTeamDetail = uow.Modules.TeamSaleDetail.Gets(teamId);


                if (obTeamDetail != null && obTeamDetail.Count > 0)
                {
                    foreach (string accountId in teamSaleIds.Split(','))
                    {
                        TeamSaleDetail detail = obTeamDetail.Find(o => o.AccountId == accountId.ParseLong());
                        detail.Approve = "1";

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

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

                if (isInsert)
                {
                    rs.Add("id", ob.TeamId);
                }
                return(isInsert ? UrlRedirect(PathHelper.AccountTeamDetail, rs) : UrlRedirect(PathHelper.AccountTeam, rs));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage();
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }