public ActionResult Create(TagViewModel model) { DebugMessage("Creating tag"); if (!ModelState.IsValid) { return JsonError("Tag model is not valid"); } var user = GetCurrentUser(); if (user == null) { return JsonError("Error retrieving user"); } var existing = Repository.GetTagByUserAndName(user.UserId, model.Name); if (existing != null) { return JsonError("Tag already exists with this name"); } var tag = new Tag() { Id = Guid.Empty, UserId = user.UserId, Name = model.Name, Type = model.Type }; if (!Repository.Create(tag)) { return JsonError("Error creating tag {0}", model.Name); } if (model.ReturnItemList.HasValue && model.ReturnItemList.Value) { var tags = Repository.GetTagsByUser(user.UserId); var tagsResponse = from t in tags select new { t.Id, t.Name, t.Type }; return Json(new { Message = Messages.Ok, Items = tagsResponse }); } return Json(new { Message = Messages.Ok }); }
private void AddTag(Tag tag) { var existing = Repository.GetTagByUserAndName(tag.UserId, tag.Name); if (existing == null) { Repository.Create(tag); } }
public bool Equals(Tag t) { return (this == t); }
public bool Create(Tag tag) { return Tags.Insert(tag, SafeMode.True).Ok; }
public bool Equals(Tag t) { if (t == null) return false; return (this == t); }