// GET: Advertise
        public async Task <ActionResult> Index()
        {
            try
            {
                var model = new AdvertisesModel();
                //Call API Provider
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var list = await APIProvider.Authorize_Get <List <AdvertiseViewModel> >(_userSession.BearerToken, controllerName, APIConstant.API_Resource_CMS, ARS.Get);

                model.lstAdvertiseViewModel = list.OrderBy(x => x.Id).ToList();
                model.AdvertiseViewModel    = new AdvertiseViewModel()
                {
                    IsUsed = true
                };

                ///Category List
                ViewBag.Categories = list;
                TempData["Data"]   = list;
                return(View(model));
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }
        public string getLogo()
        {
            var logo = new AdvertisesModel().getLogo();

            if (logo == null)
            {
                return("");
            }
            return(logo.url != "" ? logo.url : null);
        }
        public async Task <ActionResult> Create(AdvertiseViewModel model, HttpPostedFileBase fileUpload)
        {
            try
            {
                var token = _userSession.BearerToken;

                if (fileUpload == null)
                {
                    ModelState.AddModelError("Resouce", "Vui lòng chọn video hoặc hình ảnh");
                }
                if (ModelState.IsValid)
                {
                    if (fileUpload != null)
                    {
                        string name = "";
                        if (fileUpload.ContentType.Contains("image"))
                        {
                            FileManagement.UploadImage(fileUpload, ValueConstant.IMAGE_ADVERTISE_PATH, ref name);
                            model.Type    = (Byte)ValueConstant.MEDIA_TYPE.IMAGE;
                            model.Resouce = name;
                        }
                        else
                        {
                            FileManagement.UploadFile(fileUpload, ValueConstant.IMAGE_ADVERTISE_PATH, ref name);
                            string pathVideo = Server.MapPath(name);
                            model.Type = (byte)ValueConstant.MEDIA_TYPE.VIDEO;

                            UploadVideo(fileUpload, pathVideo);
                            model.Resouce = name;
                        }
                    }

                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);
                    var    result = await APIProvider.Authorize_DynamicTransaction <AdvertiseViewModel, bool>(model, token, strUrl, APIConstant.API_Resource_CMS, ARS.Insert);

                    if (result)
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.SUCCESS));
                    }
                    else
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var slider = new AdvertisesModel();
                    slider.lstAdvertiseViewModel = await APIProvider.Authorize_Get <List <AdvertiseViewModel> >(token, controllerName, APIConstant.API_Resource_CMS);

                    slider.AdvertiseViewModel = model;

                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(View("Index", slider));
                }
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }