Пример #1
0
        public ActionResult Index(PostInfo obj)
        {
            if (obj == null)
            {
                return(View("Details", new PostInfo()));
            }

            FileService fService = new FileService();

            fService.CheckAndSaveImage(obj, Request.Files);

            PostService          service = new PostService();
            ResultDTO <PostInfo> rs      = null;
            Task t1 = Task.Run(() => {
                rs = service.InserOrUpdate(obj);
            });

            Task t2 = Task.Run(() => {
                MenuService mService = new MenuService();
                ViewData["Menu"]     = mService.GetMenuFromXML(this.HttpContext);;
            });

            Task t3 = Task.Run(() => {
                TownService tService  = new TownService();
                ViewData["TownItems"] = tService.Get(this.HttpContext);
            });

            Task[] tasks = new Task[] { t1, t2, t3 };
            Task.WaitAll(tasks);

            if (rs.Code < 0)
            {
                _log.Error(rs.Message);
                ModelState.AddModelError("Error", rs.Message);
                return(View("Details", obj));
            }

            return(RedirectToAction("Index", "Posts", new { key = "" }));
        }