コード例 #1
0
        public async Task <IActionResult> SaveItem(IList <IFormFile> files, CategoriesAblums model)
        {
            string ControllerName      = this.ControllerContext.RouteData.Values["controller"].ToString();
            int    IdDC                = Int32.Parse(MyModels.Decode(model.Ids, API.Models.Settings.SecretId + ControllerName).ToString());
            CategoriesAblumsModel data = new CategoriesAblumsModel()
            {
                Item = model
            };

            if (ModelState.IsValid)
            {
                if (model.Id == IdDC)
                {
                    model.CreatedBy  = int.Parse(HttpContext.Request.Headers["Id"]);
                    model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]);
                    var Cat = CategoriesAblumsService.SaveItem(model);

                    foreach (IFormFile source in files)
                    {
                        string filename = ContentDispositionHeaderValue.Parse(source.ContentDisposition).FileName.Trim('"');

                        filename = this.EnsureCorrectFilename(filename);

                        using (FileStream output = System.IO.File.Create(this.GetPathAndFilename(filename)))
                        {
                            await source.CopyToAsync(output);

                            Ablums alb = new Ablums()
                            {
                                CatId      = Convert.ToInt32(Cat.N),
                                CreatedBy  = model.CreatedBy,
                                ModifiedBy = model.ModifiedBy,
                                Images     = this.GetPathAndFilename(filename)
                            };


                            AblumsService.SaveItem(alb);
                        }
                    }

                    if (model.Id > 0)
                    {
                        TempData["MessageSuccess"] = "Cập nhật thành công";
                    }
                    else
                    {
                        TempData["MessageSuccess"] = "Thêm mới thành công";
                    }
                    return(RedirectToAction("Index"));
                }
            }
            return(View(data));
        }
コード例 #2
0
        public IActionResult Index([FromQuery] SearchCategoriesAblums dto)
        {
            int    TotalItems          = 0;
            string ControllerName      = this.ControllerContext.RouteData.Values["controller"].ToString();
            CategoriesAblumsModel data = new CategoriesAblumsModel()
            {
                SearchData = dto
            };

            data.ListItems = CategoriesAblumsService.GetListPagination(data.SearchData, API.Models.Settings.SecretId + ControllerName);
            if (data.ListItems != null && data.ListItems.Count() > 0)
            {
                TotalItems = data.ListItems[0].TotalRows;
            }
            data.Pagination = new Models.Partial.PartialPagination()
            {
                CurrentPage = data.SearchData.CurrentPage, ItemsPerPage = data.SearchData.ItemsPerPage, TotalItems = TotalItems, QueryString = Request.QueryString.ToString()
            };

            return(View(data));
        }
コード例 #3
0
ファイル: AlbumsController.cs プロジェクト: chipdlk/THD
        //add a comment
        //second comment
        public IActionResult Index([FromQuery] SearchCategoriesAblums dto)
        {
            int    TotalItems          = 0;
            string ControllerName      = this.ControllerContext.RouteData.Values["controller"].ToString();
            CategoriesAblumsModel data = new CategoriesAblumsModel()
            {
                SearchData = dto
            };

            data.ListItemsAlbums = AblumsService.GetListPagination(new SearchAblums());
            List <CategoriesAblums> ListCatAblum = new List <CategoriesAblums>();

            ListCatAblum = CategoriesAblumsService.GetList();

            for (int i = 0; i < ListCatAblum.Count(); i++)
            {
                List <Ablums> tmp = new List <Ablums>();
                for (int j = 0; j < data.ListItemsAlbums.Count(); j++)
                {
                    if (ListCatAblum[i].Id == data.ListItemsAlbums[j].CatId)
                    {
                        tmp.Add(data.ListItemsAlbums[j]);
                    }
                }
                ListCatAblum[i].ListItemsAblums = tmp;
            }

            data.ListItems = ListCatAblum;
            if (data.ListItems != null && data.ListItems.Count() > 0)
            {
                TotalItems = data.ListItems[0].TotalRows;
            }
            data.Pagination = new Areas.Admin.Models.Partial.PartialPagination()
            {
                CurrentPage = data.SearchData.CurrentPage, ItemsPerPage = data.SearchData.ItemsPerPage, TotalItems = TotalItems, QueryString = Request.QueryString.ToString()
            };

            return(View(data));
        }
コード例 #4
0
        public IActionResult SaveItem(string Id = null)
        {
            CategoriesAblumsModel data = new CategoriesAblumsModel();
            string ControllerName      = this.ControllerContext.RouteData.Values["controller"].ToString();
            int    IdDC = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString());

            data.SearchData = new SearchCategoriesAblums()
            {
                CurrentPage = 0, ItemsPerPage = 10, Keyword = ""
            };
            data.ListItemsParents = CategoriesAblumsService.GetListItems();
            if (IdDC == 0)
            {
                data.Item = new CategoriesAblums();
            }
            else
            {
                data.Item            = CategoriesAblumsService.GetItem(IdDC, API.Models.Settings.SecretId + ControllerName);
                data.ListItemsAlbums = AblumsService.GetList(IdDC, API.Models.Settings.SecretId + ControllerName);
            }
            return(View(data));
        }