Ejemplo n.º 1
0
        public ActionResult Index()
        {
            //Get the logged in user model and convert to json(camelCased) to pass to React for initial rendering
            var userModel          = _reactUserService.GetReactUserModel(_orchardServices.WorkContext.CurrentUser.Id);
            var camelCaseFormatter = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var userJson  = JsonConvert.SerializeObject(userModel, camelCaseFormatter).ToString();
            var viewModel = new ReactViewModel {
                UserJson = userJson
            };

            return(View(viewModel));
        }
		public void VerifyViewModelPropertyChangedActionIsExecuted()
		{
			const string Value1 = "Value1";
			const string Value2 = "Value2";

			var viewModel = new ReactViewModel { Primary = Value1 };

			viewModel.Primary = Value2;

			viewModel.ChangesLog
				.Should().Have.SameSequenceAs(
					new Tuple<string, string>(primary, Once),
					new Tuple<string, string>(primary, Value1),
					new Tuple<string, string>(primary, Value2));
		}
Ejemplo n.º 3
0
        public ActionResult <DTO> likePost([FromBody] ReactViewModel model)
        {
            React OldReact = repository.React.FindOneByCondition(r => r.user_Id == model.userId && r.post_Id == model.postId);
            DTO   dto      = new DTO();

            try
            {
                if (OldReact == null)
                {
                    React react = new React()
                    {
                        user_Id = model.userId,
                        post_Id = model.postId,
                        isLiked = true,
                        isLoved = false
                    };
                    repository.React.Add(react);
                    dto.success = true;
                    dto.message = "You liked this post";
                }
                else if (OldReact != null && OldReact.isLiked == false)
                {
                    OldReact.isLiked = true;
                    OldReact.isLoved = false;
                    dto.success      = true;
                    dto.message      = "You liked this post";
                }
                else if (OldReact != null && OldReact.isLiked == true && OldReact.isLoved == false)
                {
                    OldReact.isLiked = false;
                    dto.success      = true;
                    dto.message      = "You unliked this post";
                }
                repository.save();
                return(Ok(dto));
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                logger.Warning(ex.StackTrace);
                dto.success = false;
                dto.message = "operation failed";
                return(Ok(dto));
            }
        }
        public void VerifyViewModelPropertyChangedActionIsExecuted()
        {
            const string Value1 = "Value1";
            const string Value2 = "Value2";

            var viewModel = new ReactViewModel {
                Primary = Value1
            };

            viewModel.Primary = Value2;

            viewModel.ChangesLog
            .Should().BeSameAs(
                new[]
            {
                new Tuple <string, string>(primary, Once),
                new Tuple <string, string>(primary, Value1),
                new Tuple <string, string>(primary, Value2)
            });
        }