示例#1
0
        private void GetJsonForDatagrid(HttpContext context)
        {
            int totalRecords = 0;
            int pageIndex    = 1;
            int pageSize     = 10;

            int.TryParse(context.Request.QueryString["page"], out pageIndex);
            int.TryParse(context.Request.QueryString["rows"], out pageSize);

            CategoryPicture bll  = new CategoryPicture();
            var             list = bll.GetList(pageIndex, pageSize, out totalRecords, "", null);

            if (list == null || list.Count == 0)
            {
                context.Response.Write("{\"total\":0,\"rows\":[]}");
                return;
            }
            StringBuilder sb = new StringBuilder();

            foreach (var model in list)
            {
                sb.Append("{\"Id\":\"" + model.Id + "\",\"OriginalPicture\":\"" + model.OriginalPicture.Replace("~", "") + "\",\"BPicture\":\"" + model.BPicture + "\",\"MPicture\":\"" + model.MPicture + "\",\"SPicture\":\"" + model.SPicture + "\",\"OtherPicture\":\"" + model.OtherPicture + "\",\"LastUpdatedDate\":\"" + model.LastUpdatedDate.ToString("yyyy-MM-dd HH:mm") + "\"},");
            }
            context.Response.Write("{\"total\":" + totalRecords + ",\"rows\":[" + sb.ToString().Trim(',') + "]}");
        }
示例#2
0
        /// <inheritdoc />
        public async Task <Result> AddCategory(CategoryDto categoryDto)
        {
            try
            {
                var picture = new Picture();

                if (categoryDto.Pictures != null)
                {
                    picture = await GetFile(categoryDto.Pictures);
                }

                var parentCategory = _context.Categories.Find(categoryDto.ParentCategoryId);

                var category = new Category
                {
                    Description     = categoryDto.Description,
                    HtmlH1          = categoryDto.HtmlH1,
                    MetaDescription = categoryDto.MetaDescription,
                    MetaKeywords    = categoryDto.MetaKeywords,
                    MetaTitle       = categoryDto.MetaTitle,
                    Name            = categoryDto.Name,
                    Sort            = categoryDto.Sort,
                    Status          = categoryDto.Status
                };

                _context.Add(category);
                _context.SaveChanges();

                if (parentCategory != null && parentCategory.Id != category.Id)
                {
                    var categoryToCategory = new CategoryCategory
                    {
                        Category1   = category,
                        Category1Id = category.Id,
                        Category2   = parentCategory,
                        Category2Id = parentCategory.Id
                    };

                    _context.Add(categoryToCategory);
                    _context.SaveChanges();
                }

                var categoryToPicture = new CategoryPicture
                {
                    Category   = category,
                    CategoryId = category.Id,
                    Picture    = picture
                };

                _context.Add(categoryToPicture);
                _context.SaveChanges();

                return(Result.Ok());
            }
            catch (Exception e)
            {
                throw new ApplicationException(e.Message);
            }
        }
示例#3
0
        /// <inheritdoc />
        public Result UpdateCategory(CategoryDto categoryDto)
        {
            var category       = _context.Categories.Find(categoryDto.Id);
            var parentCategory = _context.Categories.Find(categoryDto.ParentCategoryId);
            var picture        = GetFile(categoryDto.Pictures).Result;

            category.Description     = categoryDto.Description;
            category.HtmlH1          = categoryDto.HtmlH1;
            category.MetaDescription = categoryDto.MetaDescription;
            category.MetaKeywords    = categoryDto.MetaKeywords;
            category.MetaTitle       = categoryDto.MetaTitle;
            category.Name            = categoryDto.Name;
            category.Sort            = categoryDto.Sort;
            category.Status          = categoryDto.Status;

            _context.Update(category);
            _context.SaveChanges();

            if (parentCategory != null && parentCategory.Id != category.Id)
            {
                var categoryParent = _context.CategoryCategory.FirstOrDefault(x => x.Category1.Id == category.Id);
                if (categoryParent != null)
                {
                    _context.Remove(categoryParent);
                    _context.SaveChanges();
                }

                var categoryToCategory = new CategoryCategory
                {
                    Category1   = category,
                    Category1Id = category.Id,
                    Category2   = parentCategory,
                    Category2Id = parentCategory.Id
                };

                _context.Add(categoryToCategory);
                _context.SaveChanges();
            }

            var pictureDelete = _context.CategoryPicture.FirstOrDefault(x => x.CategoryId == category.Id);
            var pictureRemove = _context.Pictures.FirstOrDefault(x => x.Id == pictureDelete.PictureId);

            _context.Remove(pictureDelete ?? throw new ApplicationException());
            _context.Remove(pictureRemove ?? throw new ApplicationException());
            _context.SaveChanges();

            var categoryToPicture = new CategoryPicture
            {
                Category   = category,
                CategoryId = category.Id,
                Picture    = picture
            };

            _context.Add(categoryToPicture);
            _context.SaveChanges();

            return(Result.Ok());
        }
        private void Bind()
        {
            GetSearchItem();

            int totalRecords = 0;

            CategoryPicture bll = new CategoryPicture();

            rpData.DataSource = bll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
            rpData.DataBind();

            myDataAppend += "<div id=\"myDataForPage\">[{\"PageIndex\":\"" + pageIndex + "\",\"PageSize\":\"" + pageSize + "\",\"TotalRecord\":\"" + totalRecords + "\",\"QueryStr\":\"" + queryStr + "\"}]</div>";
        }
示例#5
0
        private void Bind()
        {
            if (!string.IsNullOrEmpty(funName))
            {
                int totalRecords = 0;
                switch (funName)
                {
                case "CategoryPicture":
                    CategoryPicture categorypBll = new CategoryPicture();
                    rpData.DataSource = categorypBll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
                    rpData.DataBind();

                    break;

                case "ProductPicture":
                    ProductPicture ppBll = new ProductPicture();
                    rpData.DataSource = ppBll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
                    rpData.DataBind();

                    break;

                case "SizePicture":
                    SizePicture spBll = new SizePicture();
                    rpData.DataSource = spBll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
                    rpData.DataBind();
                    break;

                case "ContentPicture":
                    ContentPicture cpBll = new ContentPicture();
                    rpData.DataSource = cpBll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
                    rpData.DataBind();
                    break;

                case "ServicePicture":
                    ServicePicture servepBll = new ServicePicture();
                    rpData.DataSource = servepBll.GetList(pageIndex, pageSize, out totalRecords, sqlWhere, parms == null ? null : parms.ToArray());
                    rpData.DataBind();
                    break;

                default:
                    break;
                }

                myDataAppend.Replace("{TotalRecord}", totalRecords.ToString());
                myDataAppend.Replace("{PageIndex}", pageIndex.ToString());
                myDataAppend.Replace("{PageSize}", pageSize.ToString());

                //myDataAppend.Append("<div code=\"myDataForPage\">[{\"PageIndex\":\"" + pageIndex + "\",\"PageSize\":\"" + pageSize + "\",\"TotalRecord\":\"" + totalRecords + "\"}]</div>");
                //myDataAppend.Append("<div code=\"myDataForDlg\">[{\"DlgId\":\"" + dlgId + "\",\"DlgHref\":\"/a/tyy.html\",\"IsMutilSelect\":\"" + isMutilSelect + "\"}]</div>");
            }
        }
示例#6
0
        public ActionResult Edit(CategoryPicture model)
        {
            var validator = new CategoryUpdateValidator(_unitOfWork).Validate(model.Category);

            if (validator.IsValid)
            {
                var parentCat = _unitOfWork.GetRepo <Category>().GetObject(x => x.Id == model.Category.ParentCategoryId);
                model.Category.SeoUrl = model.Category.ParentCategoryId == null?_seoUrlMaker.MakeSlug(model.Category.Name) : _seoUrlMaker.MakeSlug(parentCat.Name + "-" + model.Category.Name);

                model.Category.UpdateTime = DateTime.Now;
                _unitOfWork.GetRepo <Category>().Update(model.Category);
            }

            var isSuccess = _unitOfWork.Commit();

            TempData["IsSuccess"] = isSuccess;
            validator.Errors.ToList().ForEach(a =>
            {
                ModelState.AddModelError("Category." + a.PropertyName, a.ErrorMessage);
            });
            TempData["ModelState"] = ModelState;
            TempData["Message"]    = isSuccess ? "Kategori bilgileri güncelleme işlemi başarılı bir şekilde gerçekleştirildi." : "Kategori bilgileri güncelleme işlemi gerçekleştirilemedi lütfen tekrar deneyiniz.";
            return(RedirectToAction("Edit", new { model.Category.SeoUrl }));
        }
示例#7
0
        public string DelCategoryPicture(string itemAppend)
        {
            string errorMsg = string.Empty;

            try
            {
                itemAppend = itemAppend.Trim();
                if (string.IsNullOrEmpty(itemAppend))
                {
                    return(MessageContent.Submit_InvalidRow);
                }

                string[] items = itemAppend.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string   inIds = "";
                foreach (string item in items)
                {
                    inIds += string.Format("'{0}',", item);
                }

                CategoryPicture bll    = new CategoryPicture();
                var             spList = bll.GetList(" and Id in (" + inIds.Trim(',') + ")");
                if (spList != null || spList.Count() > 0)
                {
                    using (TransactionScope scope = new TransactionScope())
                    {
                        foreach (var model in spList)
                        {
                            if (!string.IsNullOrWhiteSpace(model.OriginalPicture))
                            {
                                string fullPath = Server.MapPath("~" + model.OriginalPicture);
                                if (File.Exists(fullPath))
                                {
                                    File.Delete(fullPath);
                                }
                            }
                            if (!string.IsNullOrWhiteSpace(model.BPicture))
                            {
                                string fullPath = Server.MapPath("~" + model.BPicture);
                                if (File.Exists(fullPath))
                                {
                                    File.Delete(fullPath);
                                }
                            }
                            if (!string.IsNullOrWhiteSpace(model.MPicture))
                            {
                                string fullPath = Server.MapPath("~" + model.MPicture);
                                if (File.Exists(fullPath))
                                {
                                    File.Delete(fullPath);
                                }
                            }
                            if (!string.IsNullOrWhiteSpace(model.SPicture))
                            {
                                string fullPath = Server.MapPath("~" + model.SPicture);
                                if (File.Exists(fullPath))
                                {
                                    File.Delete(fullPath);
                                }
                            }
                            if (!string.IsNullOrWhiteSpace(model.OtherPicture))
                            {
                                string fullPath = Server.MapPath("~" + model.OtherPicture);
                                if (File.Exists(fullPath))
                                {
                                    File.Delete(fullPath);
                                }
                            }
                        }

                        bll.DeleteBatch(items.ToList <object>());

                        scope.Complete();
                    }
                }

                return("1");
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }
            if (!string.IsNullOrEmpty(errorMsg))
            {
                return(MessageContent.AlertTitle_Ex_Error + ":" + errorMsg);
            }
            return("1");
        }
示例#8
0
        private void OnUpload(HttpContext context)
        {
            string errorMsg = "";

            try
            {
                int  effect              = 0;
                bool isCreateThumbnail   = ConfigHelper.GetValueByKey("IsCteateCategoryPictureThumbnail") == "1";
                UploadFilesHelper  ufh   = new UploadFilesHelper();
                HttpFileCollection files = context.Request.Files;
                foreach (string item in files.AllKeys)
                {
                    if (files[item] == null || files[item].ContentLength == 0)
                    {
                        continue;
                    }

                    string[]            paths   = ufh.Upload(files[item], "CategoryPictures", isCreateThumbnail);
                    CategoryPicture     ppBll   = new CategoryPicture();
                    CategoryPictureInfo ppModel = new CategoryPictureInfo();

                    string originalPicturePath = "";
                    string bPicturePath        = "";
                    string mPicturePath        = "";
                    string sPicturePath        = "";
                    string otherPicturePath    = "";
                    for (int i = 0; i < paths.Length; i++)
                    {
                        switch (i)
                        {
                        case 0:
                            originalPicturePath = paths[i].Replace("~", "");
                            break;

                        case 1:
                            bPicturePath = paths[i].Replace("~", "");
                            break;

                        case 2:
                            mPicturePath = paths[i].Replace("~", "");
                            break;

                        case 3:
                            sPicturePath = paths[i].Replace("~", "");
                            break;

                        case 4:
                            otherPicturePath = paths[i].Replace("~", "");
                            break;

                        default:
                            break;
                        }
                    }
                    ppModel.OriginalPicture = originalPicturePath;
                    ppModel.BPicture        = bPicturePath;
                    ppModel.MPicture        = mPicturePath;
                    ppModel.SPicture        = sPicturePath;
                    ppModel.OtherPicture    = otherPicturePath;
                    ppModel.LastUpdatedDate = DateTime.Now;
                    ppBll.Insert(ppModel);
                    effect++;
                }

                if (effect == 0)
                {
                    context.Response.Write("{\"success\": false,\"message\": \"未找到任何可上传的文件,请检查!\"}");
                    return;
                }

                context.Response.Write("{\"success\": true,\"message\": \"已成功上传文件数:" + effect + "个\"}");
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
            }

            if (errorMsg != "")
            {
                context.Response.Write("{\"success\": false,\"message\": \"" + errorMsg + "\"}");
            }
        }