public ActionResult Add(PostViewModel postModel) { if (ModelState.IsValid) { var tags = _tagRepository.GetTagEntities(postModel.Tags.Split(',').ToList()); _tagRepository.AddTags(tags); var postEntity = postModel.ToPostEntity(_tagRepository); postEntity.PostAddedDate = DateTime.Now; postEntity.PostEditedDate = postEntity.PostAddedDate; postEntity.OwnerUserID = GetUserId(); if (string.IsNullOrEmpty(postEntity.PostUrl)) { postEntity.PostUrl = UniqueUrlHelper.FindUniqueUrl(_postRepository, postEntity.PostTitle, ItemEntryType); } var biltyPostUrl = BitlyUrlService.GetBiltyPostUrl(SettingsRepository, postEntity.PostUrl); if (biltyPostUrl != null) { postEntity.BitlyUrl = biltyPostUrl; postEntity.BitlySourceUrl = postEntity.PostUrl; } var postId = _postRepository.AddPost(postEntity); if (postId > 0) { return(RedirectToAction("Edit", new { postID = postId, newlyAdded = true })); } } postModel.Title = SettingsRepository.BlogName; postModel.SharingEnabled = SettingsRepository.BlogSocialSharing; return(View(postModel)); }
public ActionResult AddTagPartial(string tagName, string token) { if (!User.IsInRole("SuperAdmin") && !User.IsInRole("Admin")) { return(RedirectToAction("Index", "Home", new { Area = "" })); } if (Request.IsAjaxRequest() && CheckToken(token)) { TagEntity tagEntity = null; var newTag = _tagRepository.GetTagEntities(new List <string> { tagName }).FirstOrDefault(); if (newTag != null) { _tagRepository.AddTags(new List <TagEntity> { newTag }); tagEntity = _tagRepository.GetAllTags().Single(t => t.TagName.ToLower() == tagName.ToLower()); } return(PartialView("Tag", tagEntity)); } throw new NotSupportedException("Request is not an ajax request/Possible unauthorized access"); }
static bool DrawCell(System.Action <T, Rect> drawCell, T element, List <T> selection, float fWidth, bool bObjectField, bool bMultiSelectable, Color selectedColor) { const string sOnGUI = "OnGUI"; bool bResult = false; if (drawCell == null) { Debug.LogError("null DrawCell Method!"); return(bResult); } var evt = Event.current; if (evt.type == EventType.ScrollWheel || evt.type == EventType.MouseDrag) { return(bResult); } ITag elementTag = element as ITag; if (elementTag != null && elementTag.Tag(sOnGUI)) { return(bResult); } GUILayoutOption wOption = GUILayout.Width(fWidth), hOption = GUILayout.Height(bObjectField ? (fWidth - EditorGUIUtility.singleLineHeight) : fWidth); bool bSelectable = selection != null; bool bSelected = bSelectable && selection.Contains(element); bool bMouseAct = false; if (evt.type == EventType.Repaint || evt.type == EventType.Layout || evt.type == EventType.MouseUp) { Rect ImgRT = Rect.zero, obRT = Rect.zero; try { using (new EditorGUILayout.VerticalScope(wOption)) { if (elementTag != null) { elementTag.AddTags(sOnGUI); } ImgRT = EditorGUILayout.GetControlRect(wOption, hOption); obRT = EditorGUILayout.GetControlRect(wOption); } }catch { } if (evt.type == EventType.MouseUp) { bMouseAct = bSelectable && evt.button == 0 && ImgRT.Contains(evt.mousePosition); } if (evt.type == EventType.Repaint) { if (bSelected) { EditorGUI.DrawRect(ImgRT, selectedColor); } drawCell(element, ImgRT); EditorGUI.ObjectField(obRT, element, typeof(Sprite), allowSceneObjects: false); } if (elementTag != null) { elementTag.RemoveTags(sOnGUI); } } if (bMouseAct) { if (evt.type == EventType.MouseUp) { if (!bSelected) { if (!bMultiSelectable) { selection.Clear(); } selection.Add(element); bResult = true; } else { selection.Remove(element); bResult = true; } Event.current.Use(); } if (evt.type == EventType.MouseDrag) { DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = selection.ToArray(); DragAndDrop.StartDrag("Dragging Magic Wands"); Event.current.Use(); } } return(bResult); }