Ejemplo n.º 1
0
        public void AddToDoMessages(string userName, IEnumerable<TodoMessageDto> list)
        {
            //if (!ValidateEnumerableParam(list)) return;

            using (var context = new TodoDBEntities())
            {
                var user = context.Users.FirstOrDefault(x => x.UserName == userName);

                foreach (var item in list)
                {
                    var msg = context.TodoMessages.CreateObject();
                    msg.IsCompleted = item.IsCompleted;
                    msg.PriorityID = (int)item.Priority;
                    msg.Person = item.Person;
                    msg.Message = item.Message;
                    msg.Users = user;

                    context.TodoMessages.AddObject(msg);
                    context.SaveChanges();
                }
            }

            this.RunPriorityWorkflow(userName, list);
            //using (var callback = new TodoServiceCallbackClient())
            //    callback.OnAddToDoMessagesComplete(userName, true);
        }
Ejemplo n.º 2
0
        public bool ValidateUser(string userName)
        {
            if (string.IsNullOrWhiteSpace(userName))
                throw new ArgumentException("argument userName is null or empty");

            bool result = false;
            using (var context = new TodoDBEntities())
            {
                var user = context.Users.Where(u => u.UserName == userName).FirstOrDefault();
                result = user != null;
            }

            return result;
        }
Ejemplo n.º 3
0
        public void GetPersonsList(string userName, string personKey)
        {
            //if (string.IsNullOrWhiteSpace(personKey))

            List<string> result = null;

            using (var context = new TodoDBEntities())
            {
                result = context.TodoMessages.Where(x => x.Person.IndexOf(personKey) != -1).Select(x => x.Person).Distinct().ToList();
            }

            using (var callback = new TodoServiceCallbackClient())
                callback.OnGetPersonsListComplete(userName, result);
        }
Ejemplo n.º 4
0
        public int CreateUser(string userName)
        {
            if (string.IsNullOrWhiteSpace(userName))
                throw new ArgumentException("argument userName is null or empty");

            int result = -1;
            using (var context = new TodoDBEntities())
            {
                var newUser = context.Users.CreateObject();
                newUser.UserName = userName;
                context.Users.AddObject(newUser);
                context.SaveChanges();

                result = newUser.ID;
            }
            return result;
        }
Ejemplo n.º 5
0
        public static void TodoPriorityExecute(string userName, IEnumerable<TodoMessageDto> list)
        {
            //simple logic
            using (var context = new TodoDBEntities())
            {
                var user = context.Users.FirstOrDefault(x => x.UserName == userName);

                foreach(var item in context.TodoMessages)
                {
                    if(item.PriorityID == (int)PriorityType.High)
                    {
                        item.Message = item.Message.ToUpper();
                    }
                    else
                    {
                        item.Message = item.Message.ToLower();
                    }
                }
                context.SaveChanges();
            }
        }
Ejemplo n.º 6
0
        public void GetToDoList(string userName)
        {
            List<TodoMessageDto> result = null;

            using (var context = new TodoDBEntities())
            {
                var user = context.Users.FirstOrDefault(x => x.UserName == userName);

                result = context.TodoMessages.AsEnumerable().
                    Select(x => new TodoMessageDto
                    {
                        Id = x.ID,
                        IsCompleted = x.IsCompleted,
                        Message = x.Message,
                        Person = x.Person,
                        Priority = (PriorityType)(x.PriorityID ?? 1),
                        IsOwn = user != null && x.UserID == user.ID,
                        Owner = x.Users != null ? x.Users.UserName : "******"
                    }).OrderBy(x => x.IsOwn).ToList();
            }

            using (var callback = new TodoServiceCallbackClient())
                callback.OnGetToDoListComplete(userName, result);
        }
Ejemplo n.º 7
0
        public void UpdateToDoMessages(string userName, IEnumerable<TodoMessageDto> list)
        {
            //if (!ValidateEnumerableParam(list)) return;

            using (var context = new TodoDBEntities())
            {
                var user = context.Users.FirstOrDefault(x => x.UserName == userName);

                foreach (var item in list)
                {
                    var msg = context.TodoMessages.CreateObject();
                    msg.ID = item.Id;
                    msg.IsCompleted = item.IsCompleted;
                    msg.PriorityID = (int)item.Priority;
                    msg.Person = item.Person;
                    msg.Message = item.Message;
                    msg.Users = user;

                    //context.TodoMessages.Attach(msg);
                    context.ObjectStateManager.ChangeObjectState(msg, System.Data.EntityState.Modified);
                }
                context.SaveChanges();
            }
            this.RunPriorityWorkflow(userName, list);
        }
Ejemplo n.º 8
0
        public void RemoveToDoMessages(string userName, IEnumerable<int> ids)
        {
            //if (!ValidateEnumerableParam(ids)) return;

            using (var context = new TodoDBEntities())
            {
                context.ExecuteStoreCommand(@"delete from TodoMessages  where ID in (" + string.Join(",", ids).PadRight(1) + ")");
                context.SaveChanges();
            }

            using (var callback = new TodoServiceCallbackClient())
                callback.OnRemoveToDoMessagesComplete(userName, true);
        }