Example #1
0
        public ActionResult Delete(int id, int sectionId, FormCollection collection)
        {
            var sectionItems = _sectionItemService.GetBySliderImage(id);

            foreach (var item in sectionItems)
            {
                _sectionItemService.Delete(item.Id);
            }
            _sliderImageService.Delete(id);

            return(Redirect("/Admin/SectionItem/AddSliderImage?sectionId=" + sectionId).WithSuccess("Imágen Eliminada"));
        }
Example #2
0
        public async Task <ApiResponse> Update(Slider entity)
        {
            var searchInContext = await this.sliderService.Get(x => x.Id == entity.Id);

            if (searchInContext.Status == Status.Empty)
            {
                return(new ApiResponse {
                    Message = searchInContext.Message, StatusCode = 203, DataStatus = false
                });
            }
            else if (searchInContext.Status == Status.Error)
            {
                return(new ApiResponse {
                    Message = searchInContext.Message, StatusCode = 500, DataStatus = false
                });
            }
            else if (searchInContext.Status == Status.Success)
            {//Eski Resimleri Temiz
                var sliderTemp = new List <SliderImage>();

                //Bu işlemden önce tüm resimleri sil
                //İmgLocation varsa hiçbişey yapılmayacak öylece kalacak
                //İmgLocation yoksa git ekle
                foreach (var item in searchInContext.Data.SliderImages)
                {
                    await sliderImageService.Delete(item);
                }
                if (entity.SliderImages != null)
                {
                    foreach (var item in entity.SliderImages)
                    {
                        //Resim varsa önceden sildiğim için şimdi yeniden devreye alıyorum
                        if (!string.IsNullOrEmpty(item.ImgLocation))
                        {
                            item.isDelete    = false;
                            item.isActive    = true;
                            item.UpdatedDate = DateTime.Now;
                        }
                    }
                }

                //Yeni resim işlemleri

                foreach (var item in entity.SliderImages.Where(x => x.ImgLocation == null))
                {
                    if (item.Image != null)
                    {
                        var path     = environment.WebRootPath + "\\WebBuilderContent\\Images\\Slider";
                        var fileName = fileProccesing.WriteFile(environment.WebRootPath + "\\WebBuilderContent\\Images\\Slider", item.Image).Result;
                        if (fileName != null)
                        {
                            item.ImgLocation  = "\\WebBuilderContent\\Images\\Slider\\" + fileName;
                            item.InsertedDate = DateTime.Now;
                            item.isActive     = true;
                            item.isDelete     = false;
                            item.Slider       = entity;
                            item.DeletedDate  = DateTime.MinValue;
                            item.UpdatedDate  = DateTime.MinValue;
                        }
                    }
                }
                var serviceStatus = await this.sliderService.Update(entity);

                if (serviceStatus.Status == Core.Util.Enums.Status.Success)
                {
                    return(new ApiResponse {
                        Data = serviceStatus.Data, Message = serviceStatus.Message, StatusCode = 200, DataStatus = true
                    });
                }
                else
                {
                    return(new ApiResponse {
                        Message = serviceStatus.Message, StatusCode = 500, DataStatus = false
                    });
                }
            }
            else
            {
                return(new ApiResponse {
                    Message = "Servis Erişim Hatası", StatusCode = 500, DataStatus = false
                });
            }
        }