예제 #1
0
        public ActionResult Create(TagViewModel model)
        {
            if (ModelState.IsValid)
            {
                var tag = new Tag
                {
                    Title        = model.Title.Trim(),
                    Type         = model.Type,
                    EnglishTitle = model.EnglishTitle,
                    Content      = model.Content != null?model.Content.Replace("../../content/files/editor/", "/content/files/editor/")
                                   .Replace("../content/files/editor/", "/content/files/editor/") : "",
                                       IsPublish      = model.IsPublish,
                                       IsSelected     = model.IsSelected,
                                       Instagram      = model.Instagram,
                                       Twitter        = model.Twitter,
                                       Facebook       = model.Facebook,
                                       Spotify        = model.Spotify,
                                       Website        = model.Website,
                                       Soundcloud     = model.Soundcloud,
                                       Itunes         = model.Itunes,
                                       SeoDescription = model.SeoDescription,
                                       SeoKeyword     = model.SeoKeyword
                };

                _tagService.AddNewTag(tag, model.Photo);
                _uow.SaveChanges();

                return(RedirectToAction(nameof(Index), new { type = tag.Type }));
            }
            else
            {
                return(View(model));
            }
        }
예제 #2
0
        public IHttpActionResult Post([FromBody] TagModel tagModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var tag = Mapper.Map <TagDTO>(tagModel);

                if (tagModel.Id == 0)
                {
                    tagService.AddNewTag(tag);
                }
                else
                {
                    tagService.UpdateTag(tag);
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok("Tag was added successfully"));
        }