public ActionResult Add(SalesmanViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            SalesmanBusiness business = new SalesmanBusiness();

            if (!ModelState.IsValid)
            {
                alert.Text = string.Join(System.Environment.NewLine, ModelState.Values
                                         .SelectMany(v => v.Errors)
                                         .Select(e => e.ErrorMessage));
            }
            else
            {
                business.SetUserAuth(ViewBag.UserAuth);

                alert = business.Add(model);
            }

            TempData["AlertMessage"] = alert;

            if (alert.Status == 1)
            {
                return(RedirectToAction("Index"));
            }

            return(View("Edit", model));
        }
        public ActionResult Datatable(JDatatableViewModel model)
        {
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("Index"));
            }

            JDatatableResponse resp = new JDatatableResponse();

            SalesmanBusiness business = new SalesmanBusiness();

            business.SetUserAuth(ViewBag.UserAuth);

            resp = business.GetDatatableByQuery(model);

            return(new MyJsonResult(resp, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index(string p = null)
        {
            if (string.IsNullOrEmpty(p))
            {
                p = DateTime.Now.ToString("MM-yyyy");
            }

            ViewBag.FormattedMonthYear = p;

            SalesmanBusiness business = new SalesmanBusiness();

            business.SetUserAuth(ViewBag.UserAuth);

            ViewBag.IsEditable = business.IsEditable();

            return(View());
        }
        public ActionResult Edit(int?id = null)
        {
            ViewBag.IsEdit = true;

            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            SalesmanBusiness business = new SalesmanBusiness();

            SalesmanViewModel model = business.GetDetail(id.Value);

            if (model == null)
            {
                TempData["AlertMessage"] = new AlertMessage(StaticMessage.ERR_DATA_NOT_FOUND);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }