public string Execute(string[] args) { string tagName = args[0]; if (!userSessionService.IsLoggedIn()) { throw new ArgumentException("You are not logged in!"); } tagName = tagName.ValidateOrTransform(); TagDto tagDto = new TagDto { Name = tagName }; if (!IsValid(tagDto)) { throw new ArgumentException("Invalid tag!"); } bool isTagExist = tagService.Exists(tagName); if (isTagExist) { throw new ArgumentException($"Tag {tagName} exists!"); } tagService.AddTag(tagName); return($"Tag {tagName} was added successfully!"); }
// AddTag <tag> public string Execute(string[] data) { string tagName = data[0].ValidateOrTransform(); Tag tag = service.AddTag(tagName); return($"Tag {tag.Name} was added successfully!"); }
public async Task <IActionResult> AddTag(AddTagDto tag) { var result = await _tagService.AddTag(tag); return(StatusCode(result, new { Message = "A new tag has been added" })); }
public async Task <int> AddPost(Post post, IFormFile postImageUp, string tags) { post.PostCreationDate = DateTime.Now; post.PostUpdateDate = DateTime.Now; post.PostVisit = 0; post.IsPublished = true; post.PostTitleInBrowser = TextConvertor.ReplaceLetters(TextConvertor.FixingText(post.PostTitleInBrowser), ' ', '-'); post.PostImage = postImageUp == null ? "no-image.png" : ImageTools.UploadImageNormal("no-image.png", postImageUp, "no-image.png", "wwwroot/assets/posts/image", true, "wwwroot/assets/posts/thumb", 240); if (tags != null) { var postTagAsArray = TextConvertor.TextToArray(tags, ","); var initialMiddlePostTagTableList = new List <PostTag>(); foreach (var tag in postTagAsArray) { var currentTag = TextConvertor.FixingText(tag); if (!await _tagService.ExistTag(currentTag)) { var newTagForSaveToTagsTable = new Tag { TagTitle = currentTag }; _tagService.AddTag(newTagForSaveToTagsTable); initialMiddlePostTagTableList.Add(InitialMiddlePostTagTable(post.PostId, newTagForSaveToTagsTable.TagId)); } else { var existTagInTagsTable = _tagService.GetTagByTagTitle(currentTag); initialMiddlePostTagTableList.Add(InitialMiddlePostTagTable(post.PostId, existTagInTagsTable.TagId)); } post.PostTags = initialMiddlePostTagTableList; } } await _context.Posts.AddAsync(post); await SaveChangeAsync(); await SetShortUrlToPost(post.PostId); return(post.PostId); }
public void AddTag_AddNewTag_TagShoudBeAdded() { // Arrange int countBefore = service.GetAll().Count(); TagDTO tag = new TagDTO { Id = 5, Name = "Tag 5" }; int id = tag.Id; // Act bool result = service.AddTag(tag); int countAfter = service.GetAll().Count(); // Assert Assert.IsTrue(result); Assert.AreEqual(countBefore + 1, countAfter); Assert.AreEqual(tag.Id, unitOfWork.TagManager.Get(id).Id); Assert.AreEqual(tag.Name, unitOfWork.TagManager.Get(tag.Id).Name); }
public IActionResult AddTag([FromBody] Tag tag) { if (tagService == null) { return(BadRequest(JsonConvert.SerializeObject("Null tag to add"))); } tagService.AddTag(tag); Response.Headers.Add("Message", $"tag with value:{tag.Value} was added"); return(Ok(JsonConvert.SerializeObject(tag))); }
private void AddTag(int presentId, int type, string value) { try { _tagService.AddTag(presentId, type, value); } catch (System.Exception) { ViewData["error"] = "Gaven har allerede det tag, der forsøges tilføjet"; } }
public IActionResult AddTag(String tagName) { if (String.IsNullOrEmpty(tagName)) { throw new ArgumentNullException($"{nameof(tagName)}"); } _tagService.AddTag(tagName); return(Json(new { })); }
public ActionResult Create(TagDto model) { if (ModelState.IsValid) { model.TagSum = 0; _tagService.AddTag(model); return(RedirectToAction("Index")); } BindBelongItem(); return(View(model)); }
public ActionResult Post([FromBody] Tag tag) { try { _tagService.AddTag(tag); return(Ok("New Tag Save Succesfully")); } catch (Exception) { throw new Exception("Oopps! Something went wrong"); } }
// AddTag <tag> public string Execute(params string[] data) { if (Session.User is null) { throw new ArgumentException("Invalid credentials!"); } var tag = data[0].ValidateOrTransform(); tagService.AddTag(tag); return($"{tag} was added successfully to database!"); }
public async Task <IActionResult> AddNotice(NewNotice notice) { var tagsToAdd = notice.Tags.Where(t => t.Id == 0); foreach (var t in tagsToAdd) { await _tagService.AddTag(t); } await _noticeService.AddNotice(notice); return(Ok(notice)); }
public ActionResult AddTag(TagViewModel tag, int id) { if (tag.Name != null) { Tag tagMap = Mapper.Map <TagViewModel, Tag>(tag); tagService.AddTag(id, tagMap); return(RedirectToAction("Details", "Post", new { id = id })); } else { return(RedirectToAction("Details", "Post", new { id = id })); } }
// AddTag <tagName> public string Execute(string[] data) { string tagName = data[0]; if (tagService.Exists(tagName)) { throw new DuplicateObjectException(typeof(Tag).Name, tagName); } tagName = tagName.ValidateOrTransform(); Tag tag = tagService.AddTag(tagName); return(String.Format(SuccessMessage, tagName)); }
public async Task <IActionResult> Post([FromBody] TagViewModel model) { var isSuccessResult = await _tagService.AddTag(model); if (isSuccessResult == "Unsucessfull") { return(BadRequest()); } else { var NewUri = Url.Link("TagGet", new{ id = new Guid(isSuccessResult) }); return(Created(NewUri, model)); } }
public async Task <IActionResult> Post(Tag tagRequest) { try { await _tagService.AddTag(tagRequest); } catch (ApplicationException appEx) { Log.Error(appEx.Message); return(NotFound()); } return(Ok()); }
public ActionResult Create([Bind(Exclude = "Id,Slug")] TagEntity tag) { if (ModelState.IsValid) { _tagService.AddTag(tag); if (_tagService.Commit()) { return(RedirectToAction("Index")); } ModelState.AddModelError("Save", "هنگام ثبت تگ خطایی رخ داده است."); } return(View(tag)); }
// AddTag <tag> public string Execute(string command, string[] data) { if (Session.User == null) { throw new ArgumentException("You should login first!"); } if (data.Length < 1) { throw new InvalidOperationException($"Command {command} not valid!"); } string tag = data[0].ValidateOrTransform(); return(tagService.AddTag(tag)); }
public IHttpActionResult Post([FromBody] TagViewModel tag) { if (tag == null) { return(BadRequest()); } TagDTO tagDTO = Mapper.Map <TagDTO>(tag); bool success = tagService.AddTag(tagDTO); if (success) { return(Ok()); } return(BadRequest()); }
public ActionResult AddOrUpdate(TagViewModel entity) { if (ModelState.IsValid) { if (entity.Id.HasValue) { TempData["result"] = tagService.UpdateTag(entity); } else { TempData["result"] = tagService.AddTag(entity); } } return(View()); }
public async Task Tag([Summary("time to subtract in seconds")] int seconds, [Summary("tag")][Remainder] string tag) { using (IServiceScope scope = serviceScopeFactory.CreateScope()) { ITagService tagService = scope.ServiceProvider.GetRequiredService <ITagService>(); if (IsEdit) { TimeStampDto oldTag = tagService.EditTag(Context.User.Id, Context.Message.Id, tag); logger.LogInformation($"{Context.User.Id}|{Context.User.Username} edited \"{oldTag.TagContent}\" to \"{tag}\""); } else { tagService.AddTag(tag, Context.User.Id, Context.User.Username, Context.Message.Id, seconds); logger.LogInformation($"{Context.User.Id}|{Context.User.Username} tagged {tag} with backtrack of {seconds} seconds"); } } }
public string Execute(string[] args) { var tagName = Utilities.TagUtilities.ValidateOrTransform(args[0]); if (Session.CurrentUser == null) { return(OperationNotAllowed); } if (tagService.Exists(tagName)) { return(String.Format(TagExists, tagName)); } tagService.AddTag(tagName); return(String.Format(SuccessMessage, tagName)); }
//AddTag <tag> public string Execute(string[] args) { var tag = args[0]; if (userSessionService.User != null) { throw new InvalidOperationException("Invalid credentials!"); } var tagExists = tagService.Exists(tag); if (tagExists) { throw new ArgumentException($"Tag {tag} exists"); } var tagClass = tagService.AddTag(tag); return($"Tag {tag} was added successfully!"); }
public async Task <IActionResult> CreateNewResearch(ResearchViewModel researchView) { if (ModelState.IsValid) { var researchDto = mapper.Map <ResearchDTO>(researchView); var stringedUserId = HttpContext.Session.GetString("userId"); if (!string.IsNullOrEmpty(stringedUserId)) { researchDto.AppUser = await accountManager.FindByIdAsync(stringedUserId); } else { researchDto.AppUser = await accountManager.GetUserAsync(User); } var research = await researchService.СreateNewResearch(researchDto); if (researchView.Tags != null) { var collection = researchView.Tags.Split(',') .ToList() .Select(name => new Tag { TagName = name }); foreach (var item in collection) { var tag = await tagService.FindTag(item.TagName); if (tag is null) { tag = await tagService.AddTag(item); } await tagService.AttachTag(tag, research); } } return(RedirectToAction(nameof(ResearchDetails), new { id = research.Id.ToString() })); } return(View()); }
public async Task <ActionResult> Post([FromBody] string name) { if (name == null) { return(BadRequest("Invalid tag name. ")); } TagsDomainModel domainModel = new TagsDomainModel { Name = name }; TagsDomainModel createdTag; try { createdTag = await _tagService.AddTag(domainModel); } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } if (createdTag == null) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = Messages.TAG_CREATION_ERROR, StatusCode = System.Net.HttpStatusCode.InternalServerError }; return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, errorResponse)); } return(Created("tags//" + createdTag.Id, createdTag)); }
static void Main(string[] args) { var container = new UnityContainer(); container.RegisterType <IDepartmentService, DepartmentService>(); container.RegisterType <ILibraryService, LibraryService>(); container.RegisterType <IMaterialTypeService, MaterialTypeService>(); container.RegisterType <IMenuService, MenuService>(); container.RegisterType <ITagService, TagService>(); container.RegisterType <IUserService, UserService>(); IDepartmentService departmentService = container.Resolve <IDepartmentService>(); ILibraryService libraryService = container.Resolve <ILibraryService>(); IMaterialTypeService materialTypeService = container.Resolve <IMaterialTypeService>(); IMenuService menuService = container.Resolve <IMenuService>(); ITagService tagService = container.Resolve <ITagService>(); IUserService userService = container.Resolve <IUserService>(); var lib = libraryService.AddLibrary(new Common.ViewModels.Library.LibraryViewModel { Name = "TestLiblary" }).Result; var dep = departmentService.AddDepartment(new Common.ViewModels.Department.DepartmentViewModel { Name = "Test", LibraryId = lib.Id }).Result; var mtype = materialTypeService.AddMaterialType(new Common.ViewModels.MaterialType.MaterialTypeViewModel { Name = "TestMaterialType" }).Result; var menu = menuService.AddMenu(new Common.ViewModels.Menu.MenuViewModel { Name = "Test Menu", Description = "Demo" }); var tegData = tagService.AddTag(new Common.ViewModels.Tag.TagViewModel { Name = "TestTag" }); var userData = userService.AddUser(new Common.ViewModels.User.UserPostViewModel { Username = "******", IsActive = true, Mail = "*****@*****.**" }); }
public override void OnEntry(Message message) { Logger.Current.Informational("Request received for processing TagAdd state." + ", message: " + message.MessageId); WorkflowAddTagResponse response = tagService.AddTag(new WorkflowAddTagRequest() { TagId = EntityId, ContactId = message.ContactId, CreatedBy = CreatedBy, AccountId = message.AccountId }); if (response.Exception == null) { workflowService.InsertContactWorkflowAudit(new InsertContactWorkflowAuditRequest() { WorkflowId = WorkflowId, WorkflowActionId = StateId, ContactId = message.ContactId, AccountId = message.AccountId, MessageId = message.MessageId }); } }
public async Task <IActionResult> Post([FromBody] TagInputDto model) { var newTag = await _tagService.AddTag(model); return(Ok(newTag)); }
public int Post(IdNameModel tag) { return(_tagService.AddTag(tag)); }
public async Task <ResultEntityBase> Add([FromBody] Tag tag) { return(await _itagService.AddTag(tag)); }