Example #1
0
        public ActionResult AddTag(TagModel model)
        {
            var tag = new Tag();

            if (ModelState.IsValid)
            {
                tag.Description = model.Description;
                tag.InsertDate = DateTime.Now;
                tag.InsertUserId = CustomMembership.CurrentUser().Id;
                tag.IsActive = model.IsActive;
                tag.Name = model.Name;

                try
                {
                    _tagService.Insert(tag);
                    _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);
                }
            }

            return View(model);
        }
Example #2
0
 public void Update(Tag tag)
 {
     _tagRepository.Update(tag);
 }
Example #3
0
 public void Delete(Tag tag)
 {
     _tagRepository.Delete(tag);
 }
Example #4
0
 public void Insert(Tag tag)
 {
     _tagRepository.Insert(tag);
 }
Example #5
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 PictureGaleryId in model.SelectedPictureGaleryIds)
                    {
                        post.Galeries.Add(_PictureGaleryService.Find(PictureGaleryId));
                    }

                    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 = _PictureGaleryService.GetAll();
            model.Authors = _membershipService.GetAllUsers();

            return View(model);
        }