public void AddTagToPayment(AddTagModel tagModel) { PaymentTag paymentTag = new PaymentTag { PaymentId = tagModel.PaymentId }; Tag tag = this.tagRepository.FindAll().ToList().SingleOrDefault(t => string.Compare(t.Code, tagModel.Code, true) == 0); if (tag is null) { tag = new Tag { Code = tagModel.Code, }; this.tagRepository.Create(tag); paymentTag.Tag = tag; } else { paymentTag.TagId = tag.Id; } this.paymentTagRepository.Create(paymentTag); this.paymentTagRepository.Save(); }
public IActionResult AddTagToPayment([FromBody] AddTagModel tagModel) { if (this.paymentService.UserHasRightToPayment(tagModel.PaymentId, this.GetUserId())) { return(this.StatusCode(StatusCodes.Status401Unauthorized)); } this.tagService.AddTagToPayment(tagModel); return(Ok()); }
public IActionResult AddTag(AddTagModel model, int id) { if (!this.articleService.DoesArticleExist(id)) { this.ViewData["Error"] = "Article does not exist."; return(this.RedirectToAction("Index", "Home")); } if (!this.ModelState.IsValid) { return(this.RedirectToAction("Details", "Article", new { id = id })); } this.tagService.AddTagToArticle(model.TagId, id); return(this.RedirectToAction("Details", "Article", new { id = id })); }
public IActionResult Tag(int id, AddTagModel newTag) { int userId = int.Parse(HttpContext.User.FindFirstValue("Id")); string[] tagNames = newTag.Tags.Split(',').Select(x => x.Trim()).ToArray(); int[] tagIds = _tagsService.Add(tagNames).ToArray(); try { _questionsTagsService.Add(userId, id, tagIds); } catch (AskMateNotAuthorizedException) { return(Forbid()); } return(RedirectToAction("Details", new { id })); }
public ActionResult AddTag(AddTagModel model) { if (!ModelState.IsValid) { model.SetAlert("Tag could not be added", AlertType.ClienError); return(JsonResultWithView(JsonActionResultType.ActionError, string.Empty, model)); } var tagConvertter = new AddTagConverter(); _customerService.AddTag(tagConvertter.ToTag(model)); return(JsonRedirectResult(JsonActionResultType.ActionSuccess, Url.Action("EditCustomer", "Customer", new { id = model.CustomerGuid }))); }
public async Task <ActionResult> AddTag(AddTagModel tag) { if (ModelState.IsValid) { string userID = User.Identity.GetUserId(); List <WhereOSApiRuuvi> apiResponse = await GetTagData(tag.GetAddress()); bool userHasTag = await UserHasTagMacAsync(userID, tag.GetAddress()); bool tagNameTaken = !string.IsNullOrEmpty(tag.AddTagName) && await TagNameTakenAsync(userID, tag.AddTagName); if (apiResponse.Count == 0 || userHasTag || tagNameTaken) { List <string> tagErrors = new List <string>(); if (userHasTag) { tagErrors.Add("Couldn't add this tag, since you have already added it!"); } if (tagNameTaken) { tagErrors.Add("Couldn't add this tag, since you have a tag with that name already!"); } if (apiResponse.Count == 0) { tagErrors.Add("No data found, check RuuviTag ID. See Help -section for more information."); } TempData["TagErrorList"] = tagErrors; TempData["ShowAddTag"] = true; TempData["TagModel"] = tag; return(RedirectToAction("Index")); } try { UnpackRawData test = new UnpackRawData(); test.UnpackAllData(apiResponse.First().data); } catch (InvalidOperationException) { TempData["TagErrorList"] = new List <string> { "Tag data is in an unsupported format." }; TempData["ShowAddTag"] = true; TempData["TagModel"] = tag; return(RedirectToAction("Index")); } var newTag = db.RuuviTagModels.Add(new RuuviTagModel { UserId = userID, TagMacAddress = tag.GetAddress(), TagName = tag.AddTagName }); await db.SaveChangesAsync(); TempData["ReturnToTag"] = newTag.TagId; return(RedirectToAction("Index")); } TempData["TagErrorList"] = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage).ToList(); TempData["ShowAddTag"] = true; TempData["TagModel"] = tag; return(RedirectToAction("Index")); }
public IActionResult AddTagToPayment([FromBody] AddTagModel tagModel) { this.tagService.AddTagToPayment(tagModel); return(Ok()); }