Beispiel #1
0
        public async Task <AdminSliderResultDto> CreateAsync(AdminCreateSliderDto model)
        {
            model.CheckArgumentIsNull(nameof(model));

            var post = await _postFactory.MakeSliderPostAsync(
                title : model.Title,
                slug : model.Slug,
                langId : model.LangId,
                enabled : model.Enabled);

            foreach (var item in model.Items)
            {
                var file = await _fileFactory.MakeAsync(item);

                var postFile = await _postFileFactory.MakeAsync(
                    file,
                    title : item.Title,
                    postId : null,
                    relatedFileId : null,
                    item.OrderNum);

                post.PostFiles.Add(postFile);
            }

            await _postRepository.AddAndSaveAsync(post);

            var result = new AdminSliderResultDto {
                Enabled = model.Enabled,
                LangId  = model.LangId,
                PostId  = post.Id,
                Slug    = post.Slug,
                Title   = post.Title
            };

            var items = new List <AdminSliderResultItemDto>();

            foreach (var file in post.PostFiles)
            {
                items.Add(new AdminSliderResultItemDto {
                    FileId     = file.FileId,
                    FilePath   = file.File.FilePath,
                    OrderNum   = file.OrderNum,
                    PostFileId = file.Id,
                    Title      = file.Title,
                    Url        = file.File.Url
                });
            }
            result.Items = items;

            return(result);
        }
Beispiel #2
0
        public IActionResult CreateSlider()
        {
            if (!AuthCheck())
            {
                return(RedirectToAction("Login", "Account", new { area = "Admin" }));
            }
            var sliderDto = new AdminCreateSliderDto();

            sliderDto.PhotoAltTag      = "tag";
            sliderDto.TopCategories    = _topRepo.FindEntities(x => !x.IsDeleted).OrderBy(x => x.NameTR).ToList();
            sliderDto.MiddleCategories = _midRepo.FindEntities(x => !x.IsDeleted).OrderBy(x => x.NameTR).ToList();
            sliderDto.SubCategories    = _subRepo.FindEntities(x => !x.IsDeleted).OrderBy(x => x.NameTR).ToList();
            sliderDto.Brands           = _brandRepo.FindEntities(x => !x.IsDeleted).OrderBy(x => x.BrandName).ToList();
            return(PartialView(sliderDto));
        }
Beispiel #3
0
        public IActionResult CreateSlider(AdminCreateSliderDto dto)
        {
            if (!AuthCheck())
            {
                return(RedirectToAction("Login", "Account", new { area = "Admin" }));
            }
            if (ModelState.IsValid)
            {
                var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".bmp" };

                if (dto.SliderPhoto != null)
                {
                    FileInfo fs  = new FileInfo(dto.SliderPhoto.FileName);
                    string   ext = Path.GetExtension(fs.Extension);

                    if (!allowedExtensions.Contains(ext.ToLower()))
                    {
                        HttpContext.Session.SetString("warning", "Lütfen sadece .jpg, .jpeg, .bmp veya .png uzantılı resim yükleyiniz.");
                        return(RedirectToAction("SliderList"));
                    }
                }
                if (dto.SliderThumbPhoto != null)
                {
                    FileInfo fs  = new FileInfo(dto.SliderThumbPhoto.FileName);
                    string   ext = Path.GetExtension(fs.Extension);

                    if (!allowedExtensions.Contains(ext.ToLower()))
                    {
                        HttpContext.Session.SetString("warning", "Lütfen sadece .jpg, .jpeg, .bmp veya .png uzantılı resim yükleyiniz.");
                        return(RedirectToAction("SliderList"));
                    }
                }
                dto.IsActive = true;
                int typee = (int)dto.SliderTargetType;

                //Hedef Marka ise
                if (typee == 2)
                {
                    dto.TargetTopCategoryId    = null;
                    dto.TargetMiddleCategoryId = null;
                    dto.TargetSubCategoryId    = null;
                    dto.TargetProductId        = null;
                    if (dto.TargetBrandId == null)
                    {
                        HttpContext.Session.SetString("warning", "Lütfen hedef markayı seçiniz.");
                        return(RedirectToAction("SliderList"));
                    }
                }
                //Hedef orta kategori ise
                if (typee == 3)
                {
                    dto.TargetSubCategoryId = null;
                    dto.TargetBrandId       = null;
                    dto.TargetProductId     = null;
                    if (dto.TargetTopCategoryId == null || dto.TargetMiddleCategoryId == null)
                    {
                        HttpContext.Session.SetString("warning", "Hedef olarak orta kategoriyi seçtiniz ancak kategorileri boş bıraktınız. Lütfen hedef ana ve orta kategoriyi seçiniz.");
                        return(RedirectToAction("SliderList"));
                    }
                    if (_midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).TopCategoryId != dto.TargetTopCategoryId)
                    {
                        HttpContext.Session.SetString("warning", "Seçtiğiniz kategorilerin birbiriyle ilişkili olması gerekmektedir.");
                        return(RedirectToAction("SliderList"));
                    }
                }
                //Hedef ürün ise
                if (typee == 4)
                {
                    dto.TargetTopCategoryId    = null;
                    dto.TargetMiddleCategoryId = null;
                    dto.TargetSubCategoryId    = null;
                    dto.TargetBrandId          = null;
                    if (dto.TargetProductName == null)
                    {
                        HttpContext.Session.SetString("warning", "Lütfen hedef ürün adını seçiniz.");
                        return(RedirectToAction("SliderList"));
                    }
                }
                //hedef alt kategori ise
                if (typee == 0)
                {
                    dto.TargetBrandId   = null;
                    dto.TargetProductId = null;
                    if (dto.TargetTopCategoryId == null || dto.TargetMiddleCategoryId == null || dto.TargetSubCategoryId == null)
                    {
                        HttpContext.Session.SetString("warning", "Hedef olarak alt kategoriyi seçtiniz ancak kategorileri boş bıraktınız.Lütfen hedef ana, orta ve alt kategorilerini seçiniz.");
                        return(RedirectToAction("SliderList"));
                    }
                    if (_subRepo.GetSubCateByIdWithJoin((int)dto.TargetSubCategoryId).MiddleCategoryId != dto.TargetMiddleCategoryId || _midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).TopCategoryId != dto.TargetTopCategoryId)
                    {
                        HttpContext.Session.SetString("warning", "Seçtiğiniz kategorilerin birbiriyle ilişkili olması gerekmektedir.");
                        return(RedirectToAction("SliderList"));
                    }
                }

                //hedef ana kategori ise
                if (typee == 1)
                {
                    dto.TargetMiddleCategoryId = null;
                    dto.TargetSubCategoryId    = null;
                    dto.TargetBrandId          = null;
                    dto.TargetProductId        = null;
                    if (dto.TargetTopCategoryId == null)
                    {
                        HttpContext.Session.SetString("warning", "Lütfen hedef ana kategoriyi seçiniz.");
                        return(RedirectToAction("SliderList"));
                    }
                }
                string page    = dto.Culture.Equals("tr") ? "sayfa" : "page";
                string categor = dto.Culture.Equals("tr") ? "kategoriler" : "categories";
                string bran    = dto.Culture.Equals("tr") ? "markalar" : "brands";
                string prodeta = dto.Culture.Equals("tr") ? "urun-detay" : "product-detail";

                if (dto.Culture.Equals("tr"))
                {
                    dto.PhotoAltTag =
                        typee == 2 ? _brandRepo.GetEntityById((int)dto.TargetBrandId).BrandName + " Markasına ait ürünler premiummedikal.com web sitesinde satılmaktadır"
                        : typee == 1 ? _topRepo.GetEntityById((int)dto.TargetTopCategoryId).HeadTitleTR
                        : typee == 3 ? _midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).HeadTitleTR
                        : typee == 0 ? _subRepo.GetEntityById((int)dto.TargetSubCategoryId).HeadTitleTR
                        : _productRepo.GetEntityById((int)dto.TargetProductId).HeadTitleTR;

                    dto.SliderHref =
                        typee == 2 ? $"/{dto.Culture}/{bran}/{_brandRepo.GetEntityById((int)dto.TargetBrandId).BandNameUrl}/{page}/1"

                       : typee == 1 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlTR}/{page}/1"

                       : typee == 3 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlTR}/{_midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).MiddleCategoryNameUrlTR}/{page}/1"

                       : typee == 0 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlTR}/{_midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).MiddleCategoryNameUrlTR}/{_subRepo.GetEntityById((int)dto.TargetSubCategoryId).SubCategoryNameUrlTR}/{page}/1"

                       : $"/{dto.Culture}/{prodeta}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).Brand.BandNameUrl}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).TopCategory.TopCategoryNameUrlTR}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).MiddleCategory?.MiddleCategoryNameUrlTR}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).SubCategory?.SubCategoryNameUrlTR}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).ProductNameUrlTR}";
                }
                else if (dto.Culture.Equals("ru"))
                {
                    dto.PhotoAltTag =
                        typee == 2 ? "Продукты бренда " + _brandRepo.GetEntityById((int)dto.TargetBrandId).BrandName + " продаются на сайте premiummedikal.com"
                        : typee == 1 ? _topRepo.GetEntityById((int)dto.TargetTopCategoryId).HeadTitleRU
                        : typee == 3 ? _midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).HeadTitleRU
                        : typee == 0 ? _subRepo.GetEntityById((int)dto.TargetSubCategoryId).HeadTitleRU
                        : _productRepo.GetEntityById((int)dto.TargetProductId).HeadTitleRU;

                    dto.SliderHref =
                        typee == 2 ? $"/{dto.Culture}/{bran}/{_brandRepo.GetEntityById((int)dto.TargetBrandId).BandNameUrl}/{page}/1"

                       : typee == 1 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlEN}/{page}/1"

                       : typee == 3 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlEN}/{_midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).MiddleCategoryNameUrlEN}/{page}/1"

                       : typee == 0 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlEN}/{_midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).MiddleCategoryNameUrlEN}/{_subRepo.GetEntityById((int)dto.TargetSubCategoryId).SubCategoryNameUrlEN}/{page}/1"

                       : $"/{dto.Culture}/{prodeta}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).Brand.BandNameUrl}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).TopCategory.TopCategoryNameUrlEN}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).MiddleCategory?.MiddleCategoryNameUrlEN}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).SubCategory?.SubCategoryNameUrlEN}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).ProductNameUrlEN}";
                }
                else
                {
                    dto.PhotoAltTag =
                        typee == 2 ? _brandRepo.GetEntityById((int)dto.TargetBrandId).BrandName + " Brand products are sold on premiummedikal.com website"
                        : typee == 1 ? _topRepo.GetEntityById((int)dto.TargetTopCategoryId).HeadTitleEN
                        : typee == 3 ? _midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).HeadTitleEN
                        : typee == 0 ? _subRepo.GetEntityById((int)dto.TargetSubCategoryId).HeadTitleEN
                        : _productRepo.GetEntityById((int)dto.TargetProductId).HeadTitleEN;

                    dto.SliderHref =
                        typee == 2 ? $"/{dto.Culture}/{bran}/{_brandRepo.GetEntityById((int)dto.TargetBrandId).BandNameUrl}/{page}/1"

                       : typee == 1 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlEN}/{page}/1"

                       : typee == 3 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlEN}/{_midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).MiddleCategoryNameUrlEN}/{page}/1"

                       : typee == 0 ? $"/{dto.Culture}/{categor}/{_topRepo.GetEntityById((int)dto.TargetTopCategoryId).TopCategoryNameUrlEN}/{_midRepo.GetEntityById((int)dto.TargetMiddleCategoryId).MiddleCategoryNameUrlEN}/{_subRepo.GetEntityById((int)dto.TargetSubCategoryId).SubCategoryNameUrlEN}/{page}/1"

                       : $"/{dto.Culture}/{prodeta}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).Brand.BandNameUrl}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).TopCategory.TopCategoryNameUrlEN}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).MiddleCategory?.MiddleCategoryNameUrlEN}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).SubCategory?.SubCategoryNameUrlEN}/{_productRepo.GetProductWithNameTR(dto.TargetProductName).ProductNameUrlEN}";
                }
                dto.SliderHref = dto.SliderHref.Replace("///", "/", StringComparison.Ordinal);
                dto.SliderHref = dto.SliderHref.Replace("//", "/", StringComparison.Ordinal);

                var  slidersDb = _mapper.Map <Slider>(dto);
                bool a         = _sliderRepo.CreateEntity(slidersDb);

                bool b = true;
                bool c = true;

                if (dto.SliderPhoto != null)
                {
                    b = ProcessSliderMainPhoto(dto.SliderPhoto, slidersDb.Id);
                }
                if (dto.SliderThumbPhoto != null)
                {
                    c = ProcessSliderThumbPhoto(dto.SliderThumbPhoto, slidersDb.Id);
                }
                if (a && b && c)
                {
                    HttpContext.Session.SetString("success", " Slider oluşturma işlemi başarılı.");
                    return(RedirectToAction("SliderList"));
                }
                else
                {
                    HttpContext.Session.SetString("warning", " Slider oluşturulurken hata oluştu. Hata kayıt altına alındı.");

                    _errorRepo.CreateEntity(new ErrorLog
                    {
                        Culture       = "tr",
                        ErrorLocation = "Admin Slider CreateSlider satır 214",
                        ErrorDetail   = $"a:{a}, b:{b}, c:{c}",
                        ErrorUrl      = HttpContext.Request.Path,
                    });
                    return(RedirectToAction("SliderList"));
                }
            }

            string messages = string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                          .Select(v => v.ErrorMessage + " " + v.Exception));

            HttpContext.Session.SetString("warning", $"{messages}, Lütfen formu eksiksiz doldurunuz.");
            return(RedirectToAction("SliderList"));
        }