Пример #1
0
 void ICMService.DeleteTodoType(TodoType todoType)
 {
     using (DomainService service = new DomainService())
     {
         service.DeleteTodoType(todoType);
     }
 }
Пример #2
0
        public async Task DelTodo()
        {
            var fakeUserid = Guid.NewGuid();
            var fakeType   = new TodoType
            {
                Name = "活动"
            };

            fakeType.AddModel(fakeUserid);
            var fakeTodo = new Todo
            {
                Title    = "明日社区活动",
                TodoType = fakeType,
                OffTime  = DateTime.Now
            };

            fakeTodo.AddModel(fakeUserid);
            _inMemoryContext.Add <Todo>(fakeTodo);
            await _inMemoryContext.SaveChangesAsync();

            Assert.Equal(1, await _inMemoryContext.Todos.Where(c => c.Id == fakeTodo.Id).Where(c => c.IsActive == true).CountAsync());
            await _todoService.DelTodoAsync(fakeTodo.Id);

            Assert.Equal(1, await _inMemoryContext.Todos.Where(c => c.Id == fakeTodo.Id).Where(c => c.IsActive == false).CountAsync());
        }
Пример #3
0
        public async Task UpdateTodo()
        {
            var fakeUserid = Guid.NewGuid();
            var fakeType   = new TodoType
            {
                Name = "活动"
            };

            fakeType.AddModel(fakeUserid);
            var fakeTodo = new Todo
            {
                Title    = "更新明日社区活动",
                TodoType = fakeType,
                OffTime  = DateTime.Now
            };

            fakeTodo.AddModel(fakeUserid);
            _inMemoryContext.Add <TodoType>(fakeType);
            _inMemoryContext.Add <Todo>(fakeTodo);
            await _inMemoryContext.SaveChangesAsync();

            fakeTodo.Title = "更新明日团队活动1";
            fakeTodo.UpdateModel(fakeUserid);
            await _todoService.UpdateTodoAsync(fakeTodo);

            var title = (await _inMemoryContext.Todos.FindAsync(fakeTodo.Id)).Title;

            Assert.Equal("更新明日团队活动1", title);
        }
        public async Task <IActionResult> PutTodoType(long id, TodoType todoType)
        {
            if (id != todoType.Id)
            {
                return(BadRequest());
            }

            _context.Entry(todoType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
 public TodoListData(TodoType todoType, string parameter, string title, string description)
 {
     this.todoType = todoType;
     this.parameter = parameter;
     this.title = title;
     this.description = description;
 }
Пример #6
0
        public void CreateTodo()
        {
            using (var client = new WebChannelFactory <ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
            {
                client.Open();
                var channel = client.CreateChannel();

                var todo = new TodoType {
                    id = 6, idSpecified = true, IsDone = false, Name = "New Item", Description = "This items should be fixed!", ExpirationDate = DateTime.Now
                };

                using (new OperationContextScope((IContextChannel)channel))
                {
                    try
                    {
                        var newId = channel.CreateTodo(todo);
                    }
                    catch (CommunicationException ex)
                    {
                        ValidateHttpStatusResponse(ex, HttpStatusCode.BadRequest);
                    }
                }

                todo.idSpecified = false;

                using (new OperationContextScope((IContextChannel)channel))
                {
                    var newId = channel.CreateTodo(todo);
                    ValidateHttpStatusResponse(HttpStatusCode.OK);

                    Assert.AreEqual(4, newId);
                }
            }
        }
Пример #7
0
        public void Send(string relatedDomain, string relatedDomainId
                         , string sendActorType, string sendActorId
                         , string receiveActorType, string receiveActorId
                         , string title, TodoLevel level = TodoLevel.一般, TodoType type = TodoType.待办
                         , string additionalData         = "")
        {
            lock (_lock)
            {
                Todo todo = new Todo
                {
                    RelatedDomain    = relatedDomain,
                    RelatedDomainId  = relatedDomainId,
                    SendActorType    = sendActorType,
                    SendActorId      = sendActorId,
                    Title            = title.Replace("有关于《", "有《"),
                    Level            = level,
                    Type             = type,
                    ActionType       = "",
                    AdditionalData   = additionalData,
                    ReceiveTime      = DateTime.Now,
                    ReceiveActorType = receiveActorType,
                    ReceiveActorId   = receiveActorId,
                    StandardDate     = null
                };

                base.BaseDal.Add(todo);
            }
        }
        public async Task <ActionResult <TodoType> > PostTodoType(TodoType todoType)
        {
            _context.TodoTypes.Add(todoType);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTodoType", new { id = todoType.Id }, todoType));
        }
Пример #9
0
        public async Task <ActionResult <IEnumerable <TodoType> > > DeleteTodoTypes(int id)
        {
            TodoType todotype = await dbContext.TodoTypes.Where(a => a.Id == id).SingleOrDefaultAsync();

            if (todotype != null)
            {
                dbContext.TodoTypes.Remove(todotype);
            }
            else
            {
                return(NotFound("Nincs ilyen tábla"));
            }


            var todos = dbContext.Todo.Where(t => t.TypeId == id).ToArray();

            if (todos.Any())
            {
                for (int i = 0; i < todos.Length; i++)
                {
                    dbContext.Todo.Remove(todos[i]);
                }
            }

            await dbContext.SaveChangesAsync();

            return(await ReOrderTodoType());
        }
Пример #10
0
        public void UpdateTodo(string todoId, TodoType todo)
        {
            try
            {
                message.Text = "UpdateTodo";

                int todoIdAsInt;
                if (!int.TryParse(todoId, out todoIdAsInt))
                {
                    SetHttpStatus(HttpStatusCode.BadRequest, HttpHeaderMessages.InvalidIdSpecified);
                    return;
                }

                if (!todo.idSpecified || todo.id != todoIdAsInt)
                {
                    SetHttpStatus(HttpStatusCode.BadRequest, HttpHeaderMessages.InvalidIdSpecified);
                    return;
                }

                var existing = _todos.First(td => td.id == todoIdAsInt);
                _todos.Remove(existing);

                _todos.Add(todo);

                // Return success
                SetHttpStatus(HttpStatusCode.OK, HttpHeaderMessages.TodoUpdatedOrCreated);
            }
            catch
            {
                SetHttpStatus(HttpStatusCode.InternalServerError, HttpHeaderMessages.InternalServerError);
            }
        }
Пример #11
0
        public int CreateTodo(TodoType todo)
        {
            try
            {
                message.Text = "CreateTodo";

                if (todo.idSpecified)
                {
                    SetHttpStatus(HttpStatusCode.BadRequest, HttpHeaderMessages.IdSpecified);
                    return(0);
                }

                var newId = _todos.Max(td => td.id) + 1;

                todo.id = newId;
                _todos.Add(todo);

                // Return success
                SetHttpStatus(HttpStatusCode.OK, HttpHeaderMessages.TodoUpdatedOrCreated);

                return(newId);
            }
            catch
            {
                SetHttpStatus(HttpStatusCode.InternalServerError, HttpHeaderMessages.InternalServerError);
                return(0);
            }
        }
Пример #12
0
        public void init()
        {
            var egyType = new TodoType();

            egyType.Id   = 1;
            egyType.Name = "Teszt";

            var TypeList = new List <TodoType> {
                egyType
            };
            var types = MockDbSet(TypeList);

            var TestTodos = new List <Todo>();

            for (int i = 0; i < 5; i++)
            {
                var t = new Todo();
                t.Deadline = DateTime.Now;
                t.Details  = $"{i} Todo";
                t.Id       = i + 1;
                t.Name     = $"{i} Todo";
                t.Type     = egyType;
                t.TypeId   = 1;
                t.Order    = i + 1;
                TestTodos.Add(t);
            }
            var TestTodosMock = MockDbSet(TestTodos);

            this.dbcontex = new Mock <IDbContext>();
            this.dbcontex.Setup(m => m.TodoTypes).Returns(types.Object);
            this.dbcontex.Setup(m => m.Todo).Returns(TestTodosMock.Object);
        }
Пример #13
0
        private List <Todo> GetTestTodos(Guid fakeUserid)
        {
            var fakeType = new TodoType
            {
                Name = "活动"
            };

            fakeType.AddModel(fakeUserid);
            var fakeTodo1 = new Todo
            {
                Title    = "社区活动",
                TodoType = fakeType,
                OffTime  = DateTime.Now
            };

            fakeTodo1.AddModel(fakeUserid);
            var fakeTodo2 = new Todo
            {
                Title    = "游园活动",
                TodoType = fakeType,
                OffTime  = DateTime.Now
            };

            fakeTodo2.AddModel(fakeUserid);
            var todos = new List <Todo>();

            todos.Add(fakeTodo1);
            todos.Add(fakeTodo2);
            return(todos);
        }
Пример #14
0
        public void UpdateTodo()
        {
            using (var server = new WebServiceHost(new TodoService(), new Uri(_hostAddress)))
                using (var client = new WebChannelFactory <ITodoApi>(new WebHttpBinding(), new Uri(_hostAddress)))
                {
                    server.Open();
                    client.Open();
                    var channel = client.CreateChannel();

                    var todo = new TodoType();

                    using (new OperationContextScope((IContextChannel)channel))
                    {
                        try
                        {
                            todo = channel.GetTodo("1");
                        }
                        catch (CommunicationException ex)
                        {
                            ValidateHttpStatusResponse(ex, HttpStatusCode.BadRequest);
                        }
                    }

                    todo.IsDone = true;

                    using (new OperationContextScope((IContextChannel)channel))
                    {
                        channel.UpdateTodo(todo.id.ToString(), todo);
                        ValidateHttpStatusResponse(HttpStatusCode.OK);
                    }
                }
        }
        public async Task <ActionResult <TodoItem> > PostTodoType(TodoType todoType)
        {
            _context.Add(todoType);
            await _context.SaveChangesAsync();

            //return CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem);
            return(CreatedAtAction(nameof(GetTodoType), new { id = todoType.Id }, todoType));
        }
Пример #16
0
        public void TestCreateTodo()
        {
            var todo = TodoType.Create(new TodoSnapshot {
                Title = "Get coffee"
            });

            Assert.Equal("Get coffee", todo.Title);
        }
Пример #17
0
        public async Task <bool> CreateTodoTypeAsync(TodoType todoType)
        {
            var specification = new BaseSpecification <TodoType>(c => c.Name == todoType.Name);
            var _todoTypes    = await _todoTypeRepository.GetAsync(specification);

            if (_todoTypes.Count > 0)
            {
                return(false);
            }
            return(await _todoTypeRepository.AddAsync(todoType));
        }
Пример #18
0
        public async Task <IActionResult> Create(TodoType todoType, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                todoType.AddModel(UserId);
                var result = await _todoService.CreateTodoTypeAsync(todoType);

                return(Redirect(returnUrl));
            }
            return(View(todoType));
        }
Пример #19
0
        public void TestNoEditTodo()
        {
            var todo = TodoType.Create(new TodoSnapshot {
                Title = "Get coffee"
            });

            Assert.Equal("Get coffee", todo.Title);

            todo.Edit("Learn Blazor");

            todo.Edit("Learn Blazor");

            Assert.Equal("Learn Blazor", todo.Title);
        }
Пример #20
0
        /// <summary>
        ///     Reverse map with validation across-the-wire representation into in-memory representation
        /// </summary>
        public static TodoCreateData FromRepresentation(
            this TodoCreateDataRepresentation todo,
            string parentId,
            TodoType type)
        {
            return(new TodoCreateData
            {
                Name = todo.Name
                       .ThrowInvalidDataExceptionIfNullOrWhiteSpace("A todo requires a name"),

                Parent = parentId
                         .ThrowInvalidDataExceptionIfNullOrWhiteSpace("A todo requires a tenant"),

                Type = type,
                Due = todo.Due,
                State = todo.State
            });
        }
Пример #21
0
        public IActionResult AddTodo(string Title, TodoType TodoType, Boolean IsUrgent, Boolean HasReminder, DateTime ReminderTime, Boolean teamWork, Boolean HasExplanation, string Explanation)
        {
            var emptyTodo = new Todo()
            {
                Title          = Title,
                TodoType       = TodoType,
                IsUrgent       = IsUrgent,
                HasReminder    = HasReminder,
                ReminderTime   = ReminderTime,
                Teamwork       = teamWork,
                HasExplanation = HasExplanation,
                Explanation    = Explanation
            };

            _context.Todos.Add(emptyTodo);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Task"));
        }
        public void TestOnAction4()
        {
            var list = TodoListType.Create(new ITodoSnapshot[]
            {
                new TodoSnapshot {
                    Title = "Get coffee"
                }
            });

            list.Unprotected();

            list.Insert(0, TodoType.Create(new TodoSnapshot {
                Title = "Learn Blazor"
            }));

            var snapshots = list.GetSnapshot <ITodoSnapshot[]>();

            Assert.Equal(2, snapshots.Length);
        }
Пример #23
0
        public async Task <ActionResult <TodoType> > ReOrderTodoTypeRowSort(List <TodoType> todos, int srcindex, int destinationindex)
        {
            TodoType swaptt = todos[srcindex];

            todos.RemoveAt(srcindex);
            todos.Insert(destinationindex, swaptt);


            int index = 1;

            foreach (var t in todos)
            {
                t.Order = index++;
            }

            await dbContext.SaveChangesAsync();

            return(Ok());
        }
Пример #24
0
        public IActionResult EditTodo(int TodoID, string Title, TodoType TodoType, Boolean HasReminder, Boolean IsUrgent, DateTime ReminderTime, Boolean Teamwork, Boolean HasExplanation, string Explanation)
        {
            if (ModelState.IsValid)
            {
                var TodoToUpdate = _context.Todos.Find(TodoID);
                TodoToUpdate.Title          = Title;
                TodoToUpdate.TodoType       = TodoType;
                TodoToUpdate.IsUrgent       = IsUrgent;
                TodoToUpdate.HasReminder    = HasReminder;
                TodoToUpdate.ReminderTime   = ReminderTime;
                TodoToUpdate.Teamwork       = Teamwork;
                TodoToUpdate.HasExplanation = HasExplanation;
                TodoToUpdate.Explanation    = Explanation;

                _context.Todos.Update(TodoToUpdate);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index", "Task"));
        }
Пример #25
0
        private Xamarin.Forms.Color GetItemColor(TodoType todoType)
        {
            switch (todoType)
            {
            case TodoType.Important:
                return(Xamarin.Forms.Color.LightCoral);

            case TodoType.Basic:
                return(Xamarin.Forms.Color.White);

            case TodoType.Indifferent:
                return(Xamarin.Forms.Color.WhiteSmoke);

            case TodoType.Hidden:
                return(Xamarin.Forms.Color.Transparent);

            default:
                return(Xamarin.Forms.Color.White);
            }
        }
Пример #26
0
        public IActionResult Index(TodoType filter)
        {
            var todos = _context.Todos.ToList();

            if (filter == 0)
            {
                return(Json(todos));
            }
            else
            {
                var todosWithSpecificTodoType = todos.Where(todo => todo.TodoType == filter).ToList();

                //todos = todos.FindAll(todo => todo.TodoType = filter);
                //foreach (TodoType filter in Enum.GetValues(typeof(Days)))
                //{
                //var model = todos.Where(todo => todo.TodoType == filter).ToList();
                //}
                return(Json(todosWithSpecificTodoType));
            }
        }
Пример #27
0
        public void UpdateTodo(string todoId, TodoType todo)
        {
            try
            {
                #region Validate XML message

                if (!IsValidMessage())
                {
                    SetHttpStatus(HttpStatusCode.BadRequest, HttpHeaderMessages.XsdValidationFailed);
                    return;
                }

                #endregion

                int todoIdAsInt;
                if (!int.TryParse(todoId, out todoIdAsInt))
                {
                    SetHttpStatus(HttpStatusCode.BadRequest, HttpHeaderMessages.InvalidIdSpecified);
                    return;
                }

                if (!todo.idSpecified || todo.id != todoIdAsInt)
                {
                    SetHttpStatus(HttpStatusCode.BadRequest, HttpHeaderMessages.InvalidIdSpecified);
                    return;
                }

                var existing = _todos.First(td => td.id == todoIdAsInt);
                _todos.Remove(existing);

                _todos.Add(todo);

                // Return success
                SetHttpStatus(HttpStatusCode.OK, HttpHeaderMessages.TodoUpdatedOrCreated);
            }
            catch (Exception exception)
            {
                _log.ErrorFormat("Error processing CreateTodo : {0}", exception);
                SetHttpStatus(HttpStatusCode.InternalServerError, HttpHeaderMessages.InternalServerError);
            }
        }
Пример #28
0
        public void TestOnAction()
        {
            var todo = TodoType.Create(new TodoSnapshot {
                Title = "Get coffee"
            });

            var list = new List <string>();

            todo.OnAction((ISerializedActionCall call) =>
            {
                var snapshot = todo.GetSnapshot <TodoSnapshot>();

                list.Add(snapshot.Title);
            });

            todo.Edit("Learn Blazor");

            Assert.Single(list);

            Assert.Equal("Learn Blazor", list[0]);
        }
Пример #29
0
        public int CreateTodo(TodoType todo)
        {
            try
            {
                #region Validate XML message

                if (!IsValidMessage())
                {
                    SetHttpStatus(HttpStatusCode.BadRequest, HttpHeaderMessages.XsdValidationFailed);
                    return(0);
                }

                #endregion

                if (todo.idSpecified)
                {
                    SetHttpStatus(HttpStatusCode.BadRequest, HttpHeaderMessages.IdSpecified);
                    return(0);
                }

                var newId = _todos.Max(td => td.id) + 1;

                todo.id = newId;
                _todos.Add(todo);

                // Return success
                SetHttpStatus(HttpStatusCode.OK, HttpHeaderMessages.TodoUpdatedOrCreated);

                return(newId);
            }
            catch (Exception exception)
            {
                _log.ErrorFormat("Error processing CreateTodo : {0}", exception);
                SetHttpStatus(HttpStatusCode.InternalServerError, HttpHeaderMessages.InternalServerError);
                return(0);
            }
        }
Пример #30
0
        public async Task CreateTodo()
        {
            var fakeUserid = Guid.NewGuid();
            var fakeType   = new TodoType
            {
                Name = "活动"
            };

            fakeType.AddModel(fakeUserid);
            var fakeTodo = new Todo
            {
                Title    = "创建明日社区活动",
                TodoType = fakeType,
                OffTime  = DateTime.Now
            };

            fakeTodo.AddModel(fakeUserid);
            await _todoService.CreateTodoAsync(fakeTodo);

            var title = await _inMemoryContext.Todos.Where(c => c.Title == fakeTodo.Title).Select(c => c.Title).FirstOrDefaultAsync();

            Assert.Equal(1, await _inMemoryContext.Todos.Where(c => c.Id == fakeTodo.Id).CountAsync());
            Assert.False(string.IsNullOrEmpty(title));
        }
Пример #31
0
        static void AddTask(string id, string groupKey, string memberKey, string description, string parentId, DateTimeOffset actionTime, TodoType todoType)
        {
            var newItem = new TodoItem
            {
                Id          = id,
                GroupKey    = groupKey,
                MemberKey   = memberKey,
                Sequence    = Todos.Count,
                Description = description,
                Kind        = todoType,
                ParentId    = parentId ?? ""
            };

            AddTask(newItem, actionTime);
        }