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

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

                uow.Modules.TeamSale.Delete(ob);
                uow.SaveChanges();
                rs["msg"]     = "ลบข้อมูลเรียบร้อยแล้ว";
                rs["msgType"] = AlertMsgType.Success;
                return(UrlRedirect(PathHelper.AccountTeam, rs));
            }
            catch (Exception ex)
            {
                rs["msg"]     = ex.GetMessage();
                rs["msgType"] = AlertMsgType.Danger;
                return(UrlRedirect(PathHelper.AccountTeam, rs));
            }
        }
Exemplo n.º 2
0
 public void Delete(TeamSale ob)
 {
     if (IsExist(ob.TeamId))
     {
         db.TeamSale.Remove(ob);
     }
 }
Exemplo n.º 3
0
        public static bool IsValid(this TeamSale ob, out string errorMsg)
        {
            errorMsg = string.Empty;
            if (ob == null)
            {
                errorMsg = "ไม่พบข้อมูล";
                return(false);
            }
            else
            {
                List <string> err = new List <string>();
                if (string.IsNullOrWhiteSpace(ob.TeamName))
                {
                    err.Add("กรุณาระบุชื่อทีม");
                }
                if (ob.ManagerId <= 0)
                {
                    err.Add("กรุณากำหนดหัวหน้าทีม");
                }

                if (err.Count() > 0)
                {
                    errorMsg = "กรุณาตรวจสอบข้อมูลต่อไปนี้";
                    foreach (string s in err)
                    {
                        errorMsg += @"{\n}- " + s;
                    }
                    return(false);
                }
                return(true);
            }
        }
Exemplo n.º 4
0
 public void Set(TeamSale ob)
 {
     if (ob.TeamId == 0)
     {
         db.TeamSale.Add(ob);
     }
     else
     {
         db.TeamSale.Update(ob);
     }
 }
Exemplo n.º 5
0
        private ActionResult ViewDetail(TeamSale ob, string msg, AlertMsgType?msgType)
        {
            try
            {
                if (ob == null)
                {
                    throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง");
                }

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    WidgetAlertModel alert = new WidgetAlertModel()
                    {
                        Message = msg
                    };
                    if (msgType.HasValue)
                    {
                        alert.Type = msgType.Value;
                    }
                    ViewBag.Alert = alert;
                }
                ViewData["optSale"] = uow.Modules.TeamSale.GetTeamAccountNotMembers();
                AccountPermission permission = new AccountPermission();
                permission = GetPermissionSale(CurrentUser.AccountId, CurrentUser.AccountId);
                ViewData["userAccount"]   = CurrentUser;
                ViewData["optPermission"] = permission;
                return(View("Detail", ob));
            }
            catch (Exception ex)
            {
                Dictionary <string, dynamic> rs = new Dictionary <string, dynamic>()
                {
                    { "msg", ex.GetMessage() },
                    { "msgType", AlertMsgType.Danger }
                };
                return(UrlRedirect(PathHelper.AccountTeam, rs));
            }
        }
Exemplo n.º 6
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));
            }
        }
Exemplo n.º 7
0
        public ActionResult Detail(int?id, string msg, AlertMsgType?msgType)
        {
            TeamSale ob = uow.Modules.TeamSale.Get(id ?? 0);

            return(ViewDetail(ob, msg, msgType));
        }
Exemplo n.º 8
0
        public AccountPermission GetPermissionSale(long accountId, long accountId2)
        {
            AccountPermission ap = new AccountPermission();

            if (accountId == 1) //admin
            {
                ap.IsManager   = true;
                ap.IsTeam      = true;
                ap.IsEdit      = true;
                ap.IsAdminTeam = true;
                return(ap);
            }
            TeamSale manager = uow.Modules.TeamSale.Manager(accountId);  //check is manager

            if (accountId2 == 0)
            {
                if (manager != null)
                {
                    ap.IsManager = true;
                }
                else
                {
                    ap.IsManager = false;
                }
                ap.IsTeam      = true;
                ap.IsEdit      = true;
                ap.IsAdminTeam = false;
                return(ap);
            }
            Team checkteam  = uow.Modules.TeamSale.CheckTeamSale(accountId);
            Team checkteam2 = uow.Modules.TeamSale.CheckTeamSale(accountId2);

            if (manager != null)
            {
                ap.IsManager = true;
                if (checkteam2 == null)
                {
                    ap.IsEdit      = false; //owner manager can edit
                    ap.IsAdminTeam = false;
                }
                else
                {
                    if (manager.ManagerId == checkteam2.ManagerId) ////team manager for owner transaction
                    {
                        ap.IsTeam      = true;
                        ap.IsEdit      = true; //owner manager can edit
                        ap.IsAdminTeam = false;
                    }
                    else
                    {
                        ap.IsTeam      = false;
                        ap.IsEdit      = false; //owner manager can edit
                        ap.IsAdminTeam = false;
                    }
                }
            }
            else
            {
                ap.IsManager = false;
                if (accountId == accountId2)  //check account login = owner transaction
                {
                    ap.IsTeam      = true;
                    ap.IsEdit      = true; //owner can edit
                    ap.IsAdminTeam = false;
                }
                else
                {
                    if (checkteam == null || checkteam2 == null)
                    {
                        ap.IsTeam      = false;
                        ap.IsEdit      = false;
                        ap.IsAdminTeam = false;
                    }
                    else
                    {
                        if (checkteam.TeamId == checkteam2.TeamId)  //check team account login = team owner transaction
                        {
                            ap.IsTeam      = true;
                            ap.IsEdit      = false; //team same but cannot edit
                            ap.IsAdminTeam = false;
                        }
                        else
                        {
                            ap.IsTeam      = false;
                            ap.IsEdit      = false;
                            ap.IsAdminTeam = false;
                        }
                    }
                }
            }
            return(ap);
        }