public WindowsViewModel()
        {
            ITcpEndPoint TcpEndPoint = Factory.CreateEndPoint();

            IChatting chatting = Factory.CreateConnectingToServer();

            IMessageContent messageContent = Factory.CreateMessageContent();

            IPerson person = Factory.CreatePerson();

            MessageList.Items = new System.Collections.ObjectModel.ObservableCollection <IMessageContent>();

            IJsonContainer container = Factory.CreateJsonContainer();

            IUserContent userContent = Factory.CreateUserContent();

            IUserValidationData userValidationData = new UserValidationData();

            ViewModels = new List <object>
            {
                new SignInViewModel(this, chatting, messageContent, person, TcpEndPoint, container, userContent),
                new LogInViewModel(this, chatting, messageContent, person, TcpEndPoint, container, userContent, userValidationData),
                new ChatViewModel(messageContent, this)
            };

            currentView = ViewModels[1];
        }
예제 #2
0
        public LogInViewModel(IWindowsViewModel windowsViewModel,
                              IChatting chatting,
                              IMessageContent messageContent,
                              IPerson person,
                              ITcpEndPoint tcpEndPoint,
                              IJsonContainer container,
                              IUserContent userContent,
                              IUserValidationData userValidationData)
        {
            _person             = person;
            _windowsViewModel   = windowsViewModel;
            _userValidationData = userValidationData;

            //firstTime = true;

            //////////////////Vecaic variant priekš sarkanās bultas
            //IsNameSet = false;
            //ArrowVisibility = "Hidden";
            ///////////////

            //GetData = new RelayCommand(GetAppruval);//already is excecuted in LogInCommand
            SwitchToSignIn = new RelayCommand(ToSignIn);

            LogInCommand = new LogInRelayCommand(Login, _windowsViewModel, GetAppruval, chatting.Receiving2,
                                                 this, messageContent, tcpEndPoint, container);



            //SetPicFamele = new RelayCommand(SetDefoultFamelePic);
            //SetPicMale = new RelayCommand(SetDefoultMalePic);
            //AddPic = new RelayCommand(AddPicture);
        }
        public Attempt <IUserContent> Save(IUserContent content)
        {
            if (Saving.IsRaisedEventCancelled(new SaveEventArgs <TUserContent>((TUserContent)content), this))
            {
                return(Attempt.Fail <IUserContent>(content, new Exception("blocked by delegated event")));
            }

            if (content.ParentKey == null)
            {
                content.ParentKey = Guid.Empty;
            }

            content.UpdatedDate = DateTime.Now;

            if (content.Key != null && content.Key != Guid.Empty)
            {
                var existing = _userRepo.Get(content.Key);
                if (existing != null)
                {
                    var updatedItem = _userRepo.Update(content);
                    return(Attempt.Succeed <IUserContent>(updatedItem));
                }
            }

            content.Key         = Guid.NewGuid();
            content.CreatedDate = DateTime.Now;

            var obj = _userRepo.Create(content);

            _cacheRefresher.RefreshAll();

            Saved.RaiseEvent(new SaveEventArgs <TUserContent>((TUserContent)obj), this);
            return(Attempt.Succeed <IUserContent>(obj));
        }
        public static IUserContent Parent(this IUserContent content, string instance = "default")
        {
            if (content.ParentKey == Guid.Empty)
            {
                return(null);
            }

            if (!UserContentContext.Current.Instances.ContainsKey(instance))
            {
                return(null);
            }

            var _instance = UserContentContext.Current.Instances[instance];

            var parent = _instance.Cache.GetCacheItem <IUserContent>(content.ParentKey.ToString());

            if (parent != null)
            {
                return(parent);
            }

            parent = _instance.Service.Get(content.ParentKey);
            if (parent != null)
            {
                _instance.Cache.InsertCacheItem <IUserContent>
                    (content.Key.ToString(), () => content, priority: CacheItemPriority.Default);
            }

            return(parent);
        }
        public static IEnumerable <IUserContent> Children(this IUserContent content, string instance = "default")
        {
            if (!UserContentContext.Current.Instances.ContainsKey(instance))
            {
                return(null);
            }

            return(UserContentContext.Current.Instances[instance].Service.GetChildren(content.Key, false));
        }
        /// <summary>
        ///  Save a bit of UserContent back to the db.
        /// </summary>
        public static Attempt <IUserContent> SaveUserContent(this UmbracoHelper umbraco,
                                                             IUserContent content, string instance = "default")
        {
            if (!UserContentContext.Current.Instances.ContainsKey(instance))
            {
                return(Attempt.Fail <IUserContent>(content, new KeyNotFoundException()));
            }

            return(UserContentContext.Current.Instances[instance].Service.Save(content));
        }
        public Attempt <IUserContent> SaveUserContent(IUserContent content, string instance = UserContent.DefaultInstance)
        {
            if (!UserContentContext.Current.Instances.ContainsKey(instance))
            {
                return(Attempt.Fail <IUserContent>(content, new Exception("No Instance")));
            }

            var _service = UserContentContext.Current.Instances[instance].Service;

            return(_service.Save(content));
        }
        public Attempt <IUserContent> Delete(IUserContent content)
        {
            if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <TUserContent>((TUserContent)content), this))
            {
                return(Attempt.Fail <IUserContent>(content, new Exception("blocked by delegated event")));
            }

            _userRepo.Delete(content.Key);

            Deleted.RaiseEvent(new DeleteEventArgs <TUserContent>((TUserContent)content), this);
            _cacheRefresher.Refresh(content.Key);

            return(Attempt.Succeed <IUserContent>(content));
        }
        public IUserContent Update(IUserContent entity)
        {
            using (var db = getDb())
            {
                var dto = Mapper.Map <TUserContentDTO>((TUserContent)entity);
                using (Transaction transaction = db.GetTransaction())
                {
                    db.Update(_tableName, "Id", dto);
                    transaction.Complete();
                }

                return(Mapper.Map <TUserContent>(dto));
            }
        }
 public static void SetProperty(this IUserContent content, string alias, string value)
 {
     if (!content.Properties.Any(x => x.PropertyAlias == alias))
     {
         content.Properties.Add(new UserContentProperty
         {
             PropertyAlias = alias,
             Value         = value
         });
     }
     else
     {
         var existing = content.Properties.FirstOrDefault(x => x.PropertyAlias == alias);
         if (existing != null)
         {
             existing.Value = value;
         }
     }
 }
        public IUserContent Create(IUserContent entity)
        {
            using (var db = getDb())
            {
                var dto = Mapper.Map <TUserContentDTO>((TUserContent)entity);
                if (dto.UserContentType.IsNullOrWhiteSpace())
                {
                    dto.UserContentType = "default";
                }

                using (Transaction transaction = db.GetTransaction())
                {
                    db.Save(_tableName, "Id", dto);
                    transaction.Complete();
                }

                return(Mapper.Map <TUserContent>(dto));
            }
        }
예제 #12
0
        public SignInViewModel(IWindowsViewModel windowsViewModel,
                               IChatting chatting,
                               IMessageContent messageContent,
                               IPerson person,
                               ITcpEndPoint tcpEndPoint,
                               IJsonContainer container,
                               IUserContent userContent)
        {
            _person           = person;
            _windowsViewModel = windowsViewModel;

            firstTime       = true;
            IsNameSet       = false;
            ArrowVisibility = "Hidden";

            SetView = new ParameterRelayCommand(_windowsViewModel, GetUserData, chatting.Receiving,
                                                this, messageContent, tcpEndPoint, container, NoNameCheck);

            SetPicFamele = new RelayCommand(SetDefoultFamelePic);
            SetPicMale   = new RelayCommand(SetDefoultMalePic);
            AddPic       = new RelayCommand(AddPicture);

            SwitchToLogin = new RelayCommand(ToLogin);
        }
예제 #13
0
 public static Attempt <IUserContent> AddComment(this IPublishedContent content, IUserContent comment)
 {
     comment.NodeKey = content.GetKey();
     return(UserContentContext.Current.Instances[Comments.Instance].Service.Save(comment));
 }
        public static TValue GetPropertyValue <TValue>(this IUserContent content, string alias, TValue defaultValue)
        {
            var item = content.GetProperty(alias);

            return(item != null ? (TValue)item.Value : defaultValue);
        }
        public static object GetPropertyValue(this IUserContent content, string alias, object defaultValue)
        {
            var item = content.GetProperty(alias);

            return(item != null ? item.Value : defaultValue);
        }
        public static string GetPropertyValue(this IUserContent content, string alias, string defaultValue)
        {
            var item = content.GetProperty(alias);

            return(item != null?item.Value.ToString() : defaultValue);
        }