Пример #1
0
        public ActionResult AddTag(AddTagViewModel model)
        {
            if (ModelState.IsValid)
            {
                Tag tg = new Tag()
                {
                    BlogId = model.BlogId,
                    Name   = model.TagString
                };

                BusinessLayerResult <Tag> res = _tagManager.Insert(tg);
                if (res.Errors.Count > 0)
                {
                    // başarısız
                    res.Errors.ForEach(x => ModelState.AddModelError("", x.Message));
                }
                else
                {
                    // başarılı
                    CacheHelper.RemoveGetBlogsWithOutDraftDeleteFromCache();
                    return(RedirectToAction("Edit", "Blog", new { @id = model.BlogId }));
                }
            }
            return(View(model));
        }
Пример #2
0
        public async Task <IHttpActionResult> Put(string username, int id, AddTagViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Tag tag = _dbContext.Tags.SingleOrDefault(x => x.TagId == id);
                if (tag != null)
                {
                    tag.Name = viewModel.Name;

                    try
                    {
                        await _dbContext.SaveChangesAsync();
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }

                    return(Ok());
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <IActionResult> Add(AddTagViewModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.Name) && await tagService.ExistsAsync(model.Name))
            {
                ModelState.AddModelError(nameof(model.Name), "Tag with the same name already exists.");
            }

            if (!ModelState.IsValid)
            {
                model.Destinations = await GetDestinations();

                return(View(model));
            }

            var id = await tagService.AddAsync(model.Name, model.SelectedDestinations);

            if (id < 1)
            {
                ModelState.AddModelError(string.Empty, "Save failed.");
                model.Destinations = await GetDestinations();

                return(View(model));
            }

            return(RedirectToAction(nameof(Add)));
        }
Пример #4
0
 public IActionResult AddTag(AddTagViewModel model)
 {
     _tagService.Add(new Tag()
     {
         TagName = model.TagName
     });
     return(RedirectToAction("Tags"));
 }
Пример #5
0
 public ActionResult AddTag(AddTagViewModel viewModel)
 {
     db.ProductTags.Add(new ProductTag {
         TagId = viewModel.TagId, ProductId = viewModel.Product.Id
     });
     db.SaveChanges();
     return(RedirectToAction("AddTags", new { productId = viewModel.Product.Id }));
 }
Пример #6
0
        public ActionResult AddTags(int productId)
        {
            ViewBag.Tags = new SelectList(db.Tags.ToList(), "TagId", "TagName");
            AddTagViewModel viewModel = new AddTagViewModel();

            viewModel.Product = db.Products.Where(x => x.Id == productId).FirstOrDefault();
            return(View(viewModel));
        }
Пример #7
0
        public IActionResult List()
        {
            List <Tag>      Gettags = tagRepo.GetAll().ToList();
            AddTagViewModel model   = new AddTagViewModel
            {
                tags = Gettags
            };

            return(View(model));
        }
Пример #8
0
        public IActionResult AddTag(AddTagViewModel model)
        {
            if (ModelState.IsValid)
            {
                var checkTag = this.dataManager.Tags.GetTag(model.Tag);

                if (checkTag == null)
                {
                    var tag = new Tag
                    {
                        Id   = Guid.NewGuid(),
                        Name = model.Tag.ToUpper()
                    };

                    this.dataManager.Tags.AddTag(tag);

                    var item = this.dataManager.Items.GetItem(model.ItemId);

                    item.ItemTags.Add(new ItemTag
                    {
                        Item   = item,
                        ItemId = item.Id,
                        Tag    = tag,
                        TagId  = tag.Id
                    });

                    this.dataManager.Items.SaveItem(item);
                    this.dataManager.Tags.SaveTag(tag);
                }
                else
                {
                    var item = this.dataManager.Items.GetItem(model.ItemId);

                    if (!item.ItemTags.Exists(it => it.ItemId == model.ItemId && it.Tag.Name.ToUpper() == model.Tag.ToUpper()))
                    {
                        item.ItemTags.Add(new ItemTag
                        {
                            Item   = item,
                            ItemId = item.Id,
                            Tag    = checkTag,
                            TagId  = checkTag.Id
                        });

                        this.dataManager.Items.SaveItem(item);
                        this.dataManager.Tags.SaveTag(checkTag);
                    }
                }

                return(Redirect($"/Items/Item/{model.ItemId}"));
            }
            else
            {
                return(View(model));
            }
        }
Пример #9
0
        public HttpResponseMessage SaveContactTags(AddTagViewModel viewModel)
        {
            SaveContactTagsResponse response = tagService.SaveContactTags(new SaveContactTagsRequest()
            {
                Contacts      = viewModel.Contacts,
                Tags          = viewModel.TagsList,
                Opportunities = viewModel.Opportunities,
                UserId        = this.UserId,
                AccountId     = this.AccountId
            });

            return(Request.BuildResponse(response));
        }
Пример #10
0
        public ActionResult AddTag(Guid?blogid)
        {
            if (blogid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AddTagViewModel model = new AddTagViewModel();

            model.BlogId = (Guid)blogid;


            return(View(model));
        }
Пример #11
0
        public IActionResult Add(AddTagViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model?.Title?.Length > 0)
                {
                    Tag tags = new Tag
                    {
                        Title = model.Title
                    };
                    tagRepo.Add(tags);
                    return(RedirectToAction("list"));
                }
            }

            return(View());
        }