Exemplo n.º 1
0
        public ActionResult Edit(Guid id)
        {
            var galery = galeryService.Find(id);

            if (galery == null)
            {
                return(HttpNotFound());
            }
            return(View(galery));
        }
Exemplo n.º 2
0
        public ActionResult EditGalery(int id)
        {
            var model  = new GaleryModel();
            var galery = _galeryService.Find(id);

            model.Description = galery.Description;
            model.Id          = galery.Id;
            model.IsActive    = galery.IsActive;
            model.Name        = galery.Name;

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult AddPost(PostModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Img.ContentLength > 0)
                {
                    var image                = model.Img;
                    var fileName             = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(image.FileName);
                    var imageDirectory       = Server.MapPath("~/Content/Images/uploads/Post");
                    var imageDirectorySmall  = Server.MapPath("~/Content/Images/uploads/Post/Small");
                    var imageDirectoryMiddle = Server.MapPath("~/Content/Images/uploads/Post/Middle");
                    var imageDirectoryBig    = Server.MapPath("~/Content/Images/uploads/Post/Big");

                    // dizin yoksa oluştur.
                    if (!Directory.Exists(imageDirectory))
                    {
                        Directory.CreateDirectory(imageDirectory);
                        Directory.CreateDirectory(imageDirectorySmall);
                        Directory.CreateDirectory(imageDirectoryMiddle);
                        Directory.CreateDirectory(imageDirectoryBig);
                    }

                    // resmi sunucuya kaydet
                    image.SaveAs(Path.Combine(imageDirectory, fileName));

                    // resmi küçük boyutta kaydet
                    ImageManager.SaveResizedImage(Image.FromFile(Path.Combine(imageDirectory, fileName)), new Size(180, 180), imageDirectorySmall, fileName);
                    ImageManager.SaveResizedImage(Image.FromFile(Path.Combine(imageDirectory, fileName)), new Size(360, 360), imageDirectoryMiddle, fileName);
                    ImageManager.SaveResizedImage(Image.FromFile(Path.Combine(imageDirectory, fileName)), new Size(720, 720), imageDirectoryBig, fileName);

                    var post = new Post();

                    post.InsertDate     = DateTime.Now;
                    post.InsertUserId   = CustomMembership.CurrentUser().Id;
                    post.IsActive       = model.IsActive;
                    post.ImgUrl         = Path.Combine("Content/Images/uploads/Post/", fileName);
                    post.ImgUrlSmall    = Path.Combine("Content/Images/uploads/Post/Small", fileName);
                    post.ImgUrlMiddle   = Path.Combine("Content/Images/uploads/Post/Middle", fileName);
                    post.ImgUrlBig      = Path.Combine("Content/Images/uploads/Post/Big", fileName);
                    post.AuthorId       = model.AuthorId;
                    post.CategoryId     = model.CategoryId;
                    post.Content        = model.Content;
                    post.Description    = model.Description;
                    post.PostPositionId = model.PositionId;
                    post.Slug           = StringManager.ToSlug(model.Title);
                    post.Source         = model.Source;
                    post.TagNames       = model.TagNames;
                    post.Title          = model.Title;

                    foreach (var galeryId in model.SelectedGaleryIds)
                    {
                        post.Galeries.Add(_galeryService.Find(galeryId));
                    }

                    var selectedTagNames = model.TagNames.Split(',');
                    model.ListTagNames = _tagService.GetAll().Select(x => x.Name).ToList();

                    foreach (var tagName in selectedTagNames)
                    {
                        // etiket sistemde kayıtlı ise
                        if (model.ListTagNames.Contains(tagName))
                        {
                            post.Tags.Add(_tagService.GetAll().FirstOrDefault(x => x.Name == tagName));
                        }
                        else
                        {
                            // etiket sistemde kayıtlı degil ise
                            var newTag = new Tag
                            {
                                Name         = tagName,
                                Description  = tagName,
                                InsertDate   = DateTime.Now,
                                InsertUserId = CustomMembership.CurrentUser().Id,
                                IsActive     = true,
                                Slug         = StringManager.ToSlug(tagName)
                            };
                            _tagService.Insert(newTag);
                            post.Tags.Add(newTag);
                        }
                    }

                    try
                    {
                        _postService.Insert(post);
                        _uow.SaveChanges();

                        messagesForView.Clear();
                        messagesForView.Add("İşlemi başarılı!");
                        Success(messagesForView);

                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        messagesForView.Clear();
                        messagesForView.Add("İşlem başarısız!");
                        messagesForView.Add(ex.Message);
                        messagesForView.Add(ex.InnerException.Message);
                        Error(messagesForView);
                    }
                }
            }

            model.Categories = _categoryService.GetAll();
            // tagnames yukarıda set ediliyor...
            model.Positions = _postService.GetAllPositions();
            model.Galeries  = _galeryService.GetAll();
            model.Authors   = _membershipService.GetAllUsers();

            return(View(model));
        }