Example #1
0
        public static void GetHashtag(HashtagEditVM vm, ref Hashtag hashtag)
        {

            if (hashtag == null)
            {
                hashtag = new Hashtag();
            }

            if (vm != null)
            {
                if (!vm.TextBG.StartsWith("#"))
                    vm.TextBG = "#" + vm.TextBG;
                if (!vm.TextEN.StartsWith("#"))
                    vm.TextEN = "#" + vm.TextEN;
                hashtag.TextBG = vm.TextBG;
                hashtag.TextEN = vm.TextEN;
            }
        }
Example #2
0
        public static HashtagEditVM GetVM(Hashtag hashtag)
        {
            var vm = new HashtagEditVM();

            if (hashtag == null)
                hashtag = new Hashtag()
                {
                    HashtagId = Guid.NewGuid()
                };

            vm.HashtagId = hashtag.HashtagId;
            vm.TextBG = hashtag.TextBG;
            vm.TextEN = hashtag.TextEN;

            if (!String.IsNullOrWhiteSpace(vm.TextBG) && vm.TextBG.StartsWith("#"))
                vm.TextBG = vm.TextBG.Substring(1);
            if (!String.IsNullOrWhiteSpace(vm.TextEN) && vm.TextEN.StartsWith("#"))
                vm.TextEN = vm.TextEN.Substring(1);

            return vm;
        }
        public virtual ActionResult Edit(HashtagEditVM vm)
        {
            if (!ModelState.IsValid)
            {
                return Json(new { success = false });
            }
            try
            {
                var hashtag = unitOfWork.HashtagRepository.GetByID(vm.HashtagId);
                if (hashtag == null)
                    hashtag = unitOfWork.HashtagRepository.Insert(new Hashtag() { HashtagId = vm.HashtagId });
                HashtagMapper.GetHashtag(vm, ref hashtag);
                unitOfWork.Save();

                return Json(new { success = true });
            }
            catch
            {
                return Json(new { success = false });
            }
        }