public ActionResult Preview(ImportMasterListViewModel model)
        {
            AlertMessage alert = new AlertMessage();

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

                alert = business.PreviewSales(model);
            }

            TempData["AlertMessage"] = alert;

            if (alert.Data != null)
            {
                TempData["ImportMasterList"] = alert.Data;

                return(View(alert.Data));
            }
            else
            {
                return(RedirectToAction("Import"));
            }
        }
        public ActionResult Import(ImportMasterListViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            model = null;

            if (TempData["ImportMasterList"] != null)
            {
                model = TempData["ImportMasterList"] as ImportMasterListViewModel;
            }

            if (model != null)
            {
                MasterListBusiness business = new MasterListBusiness();
                business.SetUserAuth(ViewBag.UserAuth);

                alert = business.ImportTagih(model);
            }

            else
            {
                alert.Text = StaticMessage.ERR_INVALID_INPUT;
            }

            TempData["AlertMessage"] = alert;

            return(RedirectToAction("Index"));
        }
        public ActionResult Index(string rayon)
        {
            MasterListBusiness business = new MasterListBusiness();

            business.SetUserAuth(ViewBag.UserAuth);

            ViewBag.ListRayon     = business.GetRayonSalesByUserAuth();
            ViewBag.SelectedRayon = rayon;
            ViewBag.IsEditable    = business.IsEditableSales();

            return(View());
        }
        public ActionResult ClearDouble(ClearDoubleViewModel model)
        {
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("Index"));
            }

            MasterListBusiness business = new MasterListBusiness();

            business.SetUserAuth(ViewBag.UserAuth);

            AlertMessage alert = business.ClearDouble(model);

            return(new MyJsonResult(alert, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Export(RayonDatatableViewModel model)
        {
            MasterListBusiness business = new MasterListBusiness();

            business.SetUserAuth(ViewBag.UserAuth);

            AlertMessage alert = business.ExportMasterListSales(model);

            if (alert.Status == 1)
            {
                var bytes = alert.Data as byte[];

                return(File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, string.Format("MasterListSales-{0}.xlsx", DateTime.UtcNow.ToUtcID().ToString("yyyyMMdd-HHmm"))));
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Datatable(RayonDatatableViewModel model)
        {
            if (!Request.IsAjaxRequest())
            {
                return(RedirectToAction("Index"));
            }

            JDatatableResponse resp = new JDatatableResponse();

            MasterListBusiness business = new MasterListBusiness();

            business.SetUserAuth(ViewBag.UserAuth);

            resp = business.GetDatatableSalesByQuery(model);

            return(new MyJsonResult(resp, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Import(ImportMasterListViewModel model)
        {
            AlertMessage alert = new AlertMessage();

            model = null;

            if (TempData["ImportMasterList"] != null)
            {
                model = TempData["ImportMasterList"] as ImportMasterListViewModel;
            }

            if (model != null)
            {
                MasterListBusiness business = new MasterListBusiness(new SmtpService());
                business.SetUserAuth(ViewBag.UserAuth);

                alert = await business.ImportSales(model);
            }
            else
            {
                alert.Text = StaticMessage.ERR_INVALID_INPUT;
            }

            TempData["AlertMessage"] = alert;

            if (alert.Data != null)
            {
                TempData["DoubleMasterList"] = alert.Data;

                return(View("Double", alert.Data));
            }
            else if (alert.Status == 1)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Import"));
            }
        }
        public ActionResult Import()
        {
            MasterListBusiness business = new MasterListBusiness();

            business.SetUserAuth(ViewBag.UserAuth);

            if (!business.IsEditableSales())
            {
                TempData["AlertMessage"] = new AlertMessage(StaticMessage.ERR_ACCESS_DENIED);

                return(RedirectToAction("Index"));
            }

            MasterImportViewModel model = null;

            if (TempData["ImportMasterList"] != null)
            {
                model = TempData["ImportMasterList"] as MasterImportViewModel;
            }

            return(View(model));
        }