コード例 #1
0
ファイル: MediaRepository.cs プロジェクト: hayry26/pavlikeCMS
 public Enum.EntityResult Update(Media modified)
 {
     try
     {
         _db.Entry(modified).State = EntityState.Modified;
         _db.SaveChanges();
         return Enum.EntityResult.Success;
     }
     catch (Exception r)
     {
         return Enum.EntityResult.Failed;
     }
 }
コード例 #2
0
ファイル: MediaRepository.cs プロジェクト: hayry26/pavlikeCMS
 public Enum.EntityResult Delete(Media delete)
 {
     try
     {
         _db.Medias.Remove(delete);
         _db.SaveChanges();
         return Enum.EntityResult.Success;
     }
     catch (Exception)
     {
         return Enum.EntityResult.Failed;
     }
 }
コード例 #3
0
ファイル: MediaRepository.cs プロジェクト: hayry26/pavlikeCMS
 public Enum.EntityResult Create(Media media)
 {
     try
     {
         media.Active = true;
         _db.Medias.Add(media);
         _db.SaveChanges();
         return Enum.EntityResult.Success;
     }
     catch (Exception r)
     {
         return Enum.EntityResult.Failed;
     }
 }
コード例 #4
0
ファイル: FilesController.cs プロジェクト: hayry26/pavlikeCMS
 public bool _mediaEdit(Media media)
 {
     if (!ModelState.IsValid)
     {
         this.AddToastMessage("", "Alanları kontrol edniz", Enum.ToastrType.Warning);
         return false;
     }
     var res = new MediaRepository().Update(media);
     if (res == Enum.EntityResult.Failed)
     {
         this.AddToastMessage("", "Görsel kaydedilirken hata", Enum.ToastrType.Error);
         return false;
     }
     this.AddToastMessage("", "Görsel kaydedildi.", Enum.ToastrType.Success);
     return true;
 }
コード例 #5
0
ファイル: FilesController.cs プロジェクト: hayry26/pavlikeCMS
        public void AlbumMediaUpload(int albumId)
        {

            var file = Request.Files[0];

            if (!(file?.ContentLength > 0)) return;
            var res = FileSave(file, "Media", Enum.FileType.Media);
            if (res == null)
            {
                this.AddToastMessage("", "Dosya yüklenirken hata!");
                return;
            }
            var media = new Media
            {
                Active = true,
                AuthorId = new AuthenticatedAuthor().Id,
                CreateDateTime = DateTime.Now,
                FileId = res.Id,
                Title = res.Title

            };
            if (new MediaRepository().Create(media) == Enum.EntityResult.Success)
            {

                if (new AlbumMediaRepository().Create(new AlbumMedia { AlbumId = albumId, MediaId = media.Id }) !=
                    Enum.EntityResult.Success)
                {
                    this.AddToastMessage("", "Album kaydedilirken hata");
                }
            }
            else
            {
                this.AddToastMessage("", "Album kaydedilirken hata");
            }

        }
コード例 #6
0
        public HttpStatusCode MediaCreate(HttpPostedFileBase file)
        {
            //var file = Request.Files[0];

            if (!(file?.ContentLength > 0)) return HttpStatusCode.NoContent;
            var res = FileSave(file, "Media", Enum.FileType.Media);
            if (res == null)
            {
                return HttpStatusCode.InternalServerError;
            }
            var media = new Media
            {
                Active = true,
                AuthorId = new AuthenticatedAuthor().Id,
                CreateDateTime = DateTime.Now,
                FileId = res.Id,
                Title = res.Title
            };
            return new MediaRepository().Create(media) == Enum.EntityResult.Failed ? HttpStatusCode.InternalServerError : HttpStatusCode.OK;
        }
コード例 #7
0
        public ActionResult _Create(Article model, HttpPostedFileBase photo)
        {
            if (!ModelState.IsValid)
            {
                this.AddToastMessage("", "Alanları kontrol Ediniz", Enum.ToastrType.Warning);
                ViewBag.ArticleTypeId = new SelectList(new ArticleRepository().Types(), "Id", "Title", model.ArticleTypeId);
                ViewBag.PageId = new SelectList(new PageRepository().GetAll(), "Id", "Title", model.PageId);
                return View(model);
            }

            if (photo?.ContentLength > 0)
            {
                var photofile = FileSave(photo, "Media", Enum.FileType.Media);
                if (photofile != null)
                {
                    var media = new Media
                    {
                        FileId = photofile.Id,
                        Active = true,
                        AuthorId = new AuthenticatedAuthor().Id,
                        CreateDateTime = DateTime.Now,
                        AltText = model.Title,
                        Description = model.Title,
                        Title = model.Title
                    };
                    if (new MediaRepository().Create(media) == Enum.EntityResult.Success)
                    {
                        this.AddToastMessage("", "Logo yüklendi", Enum.ToastrType.Success);
                        model.MediaId = media.Id;
                    }
                    else
                    {
                        FileDelete(photofile);
                        this.AddToastMessage("", "Logo yüklenirken hata", Enum.ToastrType.Error);
                        this.AddToastMessage("", "Sayfayı yenileyin ve tekrar deneyin.");
                    }

                }
                else
                {
                    this.AddToastMessage("", "Logo yüklenirken hata", Enum.ToastrType.Error);
                    this.AddToastMessage("", "Sayfayı yenileyin ve tekrar deneyin.");
                }
            }

            model.Permalink = Helper.CharacterCorrection(model.Title);
            model.AuthorId = new AuthenticatedAuthor().Id;
            var res = new ArticleRepository().Create(model);
            if (res == Enum.EntityResult.Failed)
            {
                this.AddToastMessage("", "Makale oluşturulurken hata", Enum.ToastrType.Error);
                ViewBag.ArticleTypeId = new SelectList(new ArticleRepository().Types(), "Id", "Title", model.ArticleTypeId);
                ViewBag.PageId = new SelectList(new PageRepository().GetAll(), "Id", "Title", model.PageId);
                return View(model);
            }

            this.AddToastMessage("", "Kayıt Başarılı", Enum.ToastrType.Success);
            return RedirectToAction("Index");
        }
コード例 #8
0
        public ActionResult Index(Settings settings, HttpPostedFileBase logoFile)
        {
            if (!ModelState.IsValid)
            {
                this.AddToastMessage("", "Alanları kontrol ediniz.", Enum.ToastrType.Warning);
                return View(settings);
            }
            if (logoFile?.ContentLength > 0)
            {
                var logo = FileSave(logoFile, "Media", Enum.FileType.Media);
                if (logo != null)
                {
                    var media = new Media
                    {
                        FileId = logo.Id,
                        Active = true,
                        AuthorId = new AuthenticatedAuthor().Id,
                        CreateDateTime = DateTime.Now,
                        AltText = settings.Title,
                        Description = settings.Description,
                        Title = settings.Title
                    };
                    if (new MediaRepository().Create(media) == Enum.EntityResult.Success)
                    {
                        this.AddToastMessage("", "Logo yüklendi", Enum.ToastrType.Success);
                        settings.LogoId = media.Id;
                    }
                    else
                    {
                        FileDelete(logo);
                        this.AddToastMessage("", "Logo yüklenirken hata", Enum.ToastrType.Error);
                        this.AddToastMessage("", "Sayfayı yenileyin ve tekrar deneyin.");
                    }

                }
                else
                {
                    this.AddToastMessage("", "Logo yüklenirken hata", Enum.ToastrType.Error);
                    this.AddToastMessage("", "Sayfayı yenileyin ve tekrar deneyin.");
                }
            }

            if (_repository.Update(settings) == Enum.EntityResult.Failed)
            {
                this.AddToastMessage("", "Ayarlar kaydedilirken hata", Enum.ToastrType.Error);
                return View(settings);
            }
            this.AddToastMessage("", "Ayarlar kaydedildi", Enum.ToastrType.Success);
            return RedirectToAction("Index");
        }
コード例 #9
0
ファイル: MediaRepository.cs プロジェクト: hayry26/pavlikeCMS
 public Enum.EntityResult Disable(Media disable)
 {
     disable.Active = false;
     return Update(disable);
 }