Esempio n. 1
0
        /// <summary>
        /// Get by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Category view model</returns>
        // GET api/values/5
        public async Task <GalleryStoreViewModel> GetById(string id)
        {
            List <string> list = new List <string> {
                "id"
            };
            var para = APIProvider.APIDefaultParameter(list, id);

            var source = await _gallery.SingleQuery(para);

            GalleryStoreViewModel dest = Mapper.Map <GalleryStoreViewModel>(source);

            return(dest);
        }
        public async Task <ActionResult> Upload(FormCollection form, List <HttpPostedFileBase> fileUpload)
        {
            var parentId = Request.Form["ParentModel.Id"];

            if (parentId != null && fileUpload != null && fileUpload.Count > 0)
            {
                // List<string> data = null;

                foreach (var item in fileUpload)
                {
                    if (item != null)
                    {
                        var model = new GalleryStoreViewModel();
                        model.Id       = Guid.NewGuid().ToString();
                        model.Img      = item.FileName;
                        model.ParentId = parentId;

                        //Call API Provider
                        string strUrl = APIProvider.APIGenerator("GalleryStore", APIConstant.ACTION_INSERT);
                        var    result = await APIProvider.Authorize_DynamicTransaction <GalleryStoreViewModel, bool>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CMS, ARS.Edit);

                        if (result)
                        {
                            var path = Path.Combine(ValueConstant.IMAGE_GALLERY_PATH);
                            var up   = FileManagement.UploadImage(item, path);
                            if (!up)
                            {
                                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, "Có lỗi phát sinh khi upload hình ảnh lên bộ sưu tập: [" + model.Img + "]");
                                return(RedirectToAction("Store", new { parentId = parentId }));
                            }
                            // data.Add(Path.Combine(path, item.FileName));
                        }
                        else
                        {
                            TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, "Có lỗi phát sinh khi upload hình ảnh lên bộ sưu tập: [" + model.Img + "]");
                            return(RedirectToAction("Store", new { parentId = parentId }));
                        }
                    }
                }
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, "Upload hình ảnh thành công. Xin kiểm tra dữ liệu hình ảnh bộ sưu tập bên dưới.");
            }
            else
            {
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, "Không có file được chọn hoặc có lỗi phát sinh khi upload hình ảnh bộ sưu tập.");
            }

            return(RedirectToAction("Store", new { parentId = parentId }));
        }
Esempio n. 3
0
        public async Task <bool> Transaction(GalleryStoreViewModel model, char action)
        {
            var obj = Mapper.Map <Domain.Models.CMS.GalleryStore>(model);

            return(await _gallery.Transaction(obj, action));
        }