Ejemplo n.º 1
0
        // GET: Post/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            try
            {
                if (!await APIProvider.Authorization(_userSession.BearerToken, ARS.Edit))
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.Account, APIConstant.ACTION_UPDATE);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var listPri = new InitPriority();
                    ViewBag.Priorities = listPri.InitItemPriority();

                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(this, this.RouteData.Values["action"].ToString(), id);
                    var    model  = await APIProvider.Authorize_Get <PostViewModel>(_userSession.BearerToken, controllerPost + strUrl, APIConstant.API_Resource_CMS, ARS.Get);

                    if (string.IsNullOrEmpty(model.Image))
                    {
                        model.Image = ValueConstant.IMAGE_PATH + ValueConstant.IMAGE_POST_PATH + ValueConstant.IMAGE_DEFAULT;
                    }
                    var listCatg = await APIProvider.Authorize_Get <List <CategoryViewModel> >(_userSession.BearerToken, controllerCategory, APIConstant.API_Resource_CMS, ARS.Get);

                    if (listCatg != null)
                    {
                        ViewBag.Categories = listCatg;
                    }
                    else
                    {
                        ViewBag.Categories = new List <CategoryViewModel>();
                    }

                    if (model.Tag != string.Empty)
                    {
                        ViewBag.Tags = model.Tag;
                    }

                    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;
            }
        }
Ejemplo n.º 2
0
        // GET: PublishPost/Details/5
        public async Task <ActionResult> Details(int id)
        {
            try
            {
                //Priority
                var listPri = new InitPriority();
                ViewBag.Priorities = listPri.InitItemPriority();

                //Post
                //string strUrl = APIProvider.APIGenerator(controllerPost, "Publish", new List<string> { nameof(id)}, id);
                string strUrl = APIProvider.APIGenerator(this, this.RouteData.Values["action"].ToString(), id);
                var    model  = await APIProvider.Authorize_Get <PostViewModel>(_userSession.BearerToken, controllerPost + strUrl, APIConstant.API_Resource_CMS, ARS.Get);

                if (string.IsNullOrEmpty(model.Image))
                {
                    model.Image = ValueConstant.IMAGE_PATH + ValueConstant.IMAGE_POST_PATH + ValueConstant.IMAGE_DEFAULT;
                }
                if (model.Tag != string.Empty)
                {
                    ViewBag.Tags = model.Tag;
                }

                //Category
                var lstCategory = await APIProvider.Authorize_Get <List <CategoryViewModel> >(_userSession.BearerToken, controllerCategory, APIConstant.API_Resource_CMS, ARS.Get);

                ViewBag.Categories = lstCategory;

                if (model.Tag != string.Empty)
                {
                    ViewBag.Tags = model.Tag;
                }

                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;
            }
        }
Ejemplo n.º 3
0
        // GET: Post/Create
        public async Task <ActionResult> Create()
        {
            try
            {
                if (!await APIProvider.Authorization(_userSession.BearerToken, ARS.Insert))
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.Article, APIConstant.ACTION_INSERT);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var listPri = new InitPriority();
                    ViewBag.Priorities = listPri.InitItemPriority();

                    var model = new PostViewModel();
                    model.MetaRobotFollow = model.MetaRobotIndex = model.MetaRobotAdvanced = 1;
                    model.PublishDate     = DateTime.Now;
                    model.Status          = 1;

                    var listCatg = await APIProvider.Authorize_Get <List <CategoryViewModel> >(_userSession.BearerToken, controllerCategory, APIConstant.API_Resource_CMS, ARS.Get);

                    if (listCatg != null)
                    {
                        model.CategoryId   = listCatg.FirstOrDefault(m => m.Name == "Tin tức").Id;
                        ViewBag.Categories = listCatg;
                    }
                    else
                    {
                        ViewBag.Categories = new List <CategoryViewModel>();
                    }

                    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;
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Edit(PostViewModel model, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        if (fileUpload != null)
                        {
                            if (string.IsNullOrEmpty(model.Image) || model.Image == ValueConstant.IMAGE_DEFAULT)
                            {
                                string imagePath = CreateFolder();
                                string name      = "";
                                FileManagement.UploadImage(fileUpload, imagePath, ref name);
                                model.Image = name;
                            }
                            else
                            {
                                string name      = "";
                                string directory = Path.GetDirectoryName(model.Image);
                                FileManagement.UploadImage(fileUpload, directory, ref name);
                                model.Image = name;
                            }
                        }
                        model.LanguageId = ValueConstant.LANG_VIETNAM;
                        model.Status     = 1;
                        model.ModifiedBy = _userSession.UserId;
                        model.UserId     = _userSession.UserId;

                        model.BreadcrumbsTitle = model.BreadcrumbsTitle ?? string.Empty;
                        model.Note             = model.Note ?? string.Empty;

                        var _status = model.Status;
                        model.TitleTrans       = model.TitleTrans ?? string.Empty;
                        model.DescriptionTrans = model.DescriptionTrans ?? string.Empty;
                        model.Detail           = model.Detail ?? string.Empty;
                        model.Tag = model.Tag ?? string.Empty;

                        model.TitleSEO       = model.TitleSEO ?? string.Empty;
                        model.DescriptionSEO = model.DescriptionSEO ?? string.Empty;
                        model.Canonical      = model.Canonical ?? string.Empty;

                        //Call API Provider
                        string strUrl = APIProvider.APIGenerator(controllerPost, "PostTrans", APIConstant.ACTION_UPDATE);
                        var    result = await APIProvider.Authorize_DynamicTransaction <PostViewModel, int>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CMS, ARS.IgnoredARS);

                        if (result > 0)                                          //Id has a value
                        {
                            if (_status == (int)ValueConstant.POST_STATUS.DRAFT) //Status is Draft
                            {
                                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.SUCCESS));
                                return(RedirectToAction("Edit", new { Id = result }));
                            }
                            else if (_status == (int)ValueConstant.POST_STATUS.TRASH)
                            {
                                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_DELETE, ApplicationGenerator.TypeResult.SUCCESS));
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.SUCCESS));
                                return(RedirectToAction("Index"));
                            }
                        }
                        else
                        {
                            ViewBag.Tags = model.Tag;

                            var listPri = new InitPriority();
                            ViewBag.Priorities = listPri.InitItemPriority();

                            var listCatg = await APIProvider.Authorize_Get <List <CategoryViewModel> >(_userSession.BearerToken, controllerCategory, APIConstant.API_Resource_CMS, ARS.Get);

                            if (listCatg != null)
                            {
                                ViewBag.Categories = listCatg;
                            }
                            else
                            {
                                ViewBag.Categories = new List <CategoryViewModel>();
                            }

                            TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.FAIL));
                            return(View(model));
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError(ex);
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.ERROR, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.ERROR));
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Tags = model.Tag;

                    var listPri = new InitPriority();
                    ViewBag.Priorities = listPri.InitItemPriority();

                    var listCatg = await APIProvider.Authorize_Get <List <CategoryViewModel> >(_userSession.BearerToken, controllerCategory, APIConstant.API_Resource_CMS, ARS.Get);

                    if (listCatg != null)
                    {
                        ViewBag.Categories = listCatg;
                    }
                    else
                    {
                        ViewBag.Categories = new List <CategoryViewModel>();
                    }

                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.FAIL));
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                throw;
            }
        }