Exemplo n.º 1
0
        public void GetWorkItem_OnValidRequest_ReturnsWorkItem()
        {
            // ARRANGE
            DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>()
                                                             .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                             .Options;
            IDatabaseContext   dbContext  = new TestDatabaseContext(options);
            WorkItemRepository repository = new WorkItemRepository(dbContext);
            WorkItemConverter  converter  = new WorkItemConverter(dbContext);

            WorkItem workItem = new WorkItem()
            {
                Description          = Guid.NewGuid().ToString(),
                Name                 = Guid.NewGuid().ToString(),
                WorkItemEnd          = DateTime.Now,
                WorkItemStart        = DateTime.Now,
                WorkItemCollectionId = 1
            };

            dbContext.WorkItems.Add(workItem);

            dbContext.SaveChanges();

            // ACT
            WorkItemPublic result = repository.GetWorkItem(1);

            // ASSERT
            result.Should().BeEquivalentTo <WorkItemPublic>(converter.Convert(workItem));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Konstruktor przyjmujący WorkItemDisplayViewModel
 /// </summary>
 public WorkItemDetailsViewModel(WorkItemPublic workItem, ITerminalContext context)
 {
     WorkItem      = workItem;
     mContext      = context;
     mIdentity     = nameof(WorkItemDetailsViewModel) + WorkItem.ID;
     UpdateCommand = new AsyncCommand(SaveChanges);
 }
Exemplo n.º 3
0
 public WorkItemDisplayViewModel(WorkItemPublic workItem, int dayOffset, ITerminalContext context)
 {
     WorkItem              = workItem;
     mDayOffset            = dayOffset;
     mContext              = context;
     ShowEditDialogCommand = new BasicCommand(this.ShowEditDialog);
     UpdateDisplayProperties();
 }
Exemplo n.º 4
0
 /// <summary>
 /// sprawdza czy 2 workItemy przechowują te same dane
 /// </summary>
 private bool AreWorkItemsEqualNoID(WorkItemPublic one, WorkItemPublic two)
 {
     if (one.Name == two.Name && one.Description == two.Description &&
         one.Color == two.Color && one.WorkItemStart == two.WorkItemStart && one.WorkItemEnd == two.WorkItemEnd &&
         one.WorkItemCollectionID == two.WorkItemCollectionID)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Usuwa pojedynczy WorkItem z Kolekcji, jeżeli istnieje.
        /// </summary>
        /// <param name="workItem"></param>
        public void DeleteWorkItem(WorkItemPublic workItem)
        {
            Ensure.ParamNotNull(workItem, nameof(workItem));

            CtrlWorkItemDisplay toRemove = TaskBoard.FirstOrDefault(tb => ((WorkItemDisplayViewModel)tb.DataContext).WorkItem.ID == workItem.ID);

            if (toRemove != null)
            {
                TaskBoard.Remove(toRemove);
            }
        }
Exemplo n.º 6
0
        /// <inheritdoc/>
        public WorkItemPublic UpdateWorkItem(WorkItemPublic workItem)
        {
            Ensure.ParamNotNull(workItem, nameof(workItem));

            WorkItemLogic     workItemLogic = new WorkItemLogic(mDBContext);
            WorkItemConverter converter     = new WorkItemConverter(mDBContext);

            WorkItem result = workItemLogic.UpdateWorkItem(converter.Convert(workItem));

            mDBContext.SaveChanges();

            return(converter.Convert(result));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Zapisuje zmiany
        /// </summary>
        public async Task SaveChanges()
        {
            if (string.IsNullOrEmpty(WorkItem.Name))
            {
                mContext.DialogBuilder.WarningDialog("Work Item's name is missing or incorrect");
                return;
            }
            if (WorkItem.WorkItemStart >= WorkItem.WorkItemEnd)
            {
                mContext.DialogBuilder.WarningDialog("Selected date and time are incorrect");
                return;
            }
            if (WorkItem.WorkItemEnd.Subtract(WorkItem.WorkItemStart).TotalHours > 24)
            {
                mContext.DialogBuilder.WarningDialog("Work Item cannot be longer than 24 hours");
                return;
            }

            WorkItemPublic updatedWorkItem = null;

            if (WorkItem.ID == 0)
            {
                updatedWorkItem = await CreateWorkItem().ConfigureAwait(false);

                if (updatedWorkItem == null)
                {
                    updatedWorkItem = WorkItem;
                }
            }
            else
            {
                updatedWorkItem = await UpdateWorkItem().ConfigureAwait(false);
            }

            await Application.Current.Dispatcher.BeginInvoke(() =>
            {
                if (!AreWorkItemsEqualNoID(WorkItem, updatedWorkItem) || updatedWorkItem.ID == 0)
                {
                    mContext.DialogBuilder.WarningDialog("Work Item conflicts with an existing Work Item");
                    WorkItem = updatedWorkItem;
                }
                else
                {
                    WorkItem = updatedWorkItem;
                    mContext.WorkItemMediator.UpdateWorkItem(WorkItem);
                    mContext.WorkItemMediator.AddItemToCollection(WorkItem);
                }
            });
        }
Exemplo n.º 8
0
        public void UpdateWorkItem_OnValidRequest_UpdatesWorkItem()
        {
            // ARRANGE
            DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>()
                                                             .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                                                             .Options;
            IDatabaseContext   dbContext  = new TestDatabaseContext(options);
            WorkItemRepository repository = new WorkItemRepository(dbContext);
            WorkItemPublic     workItem   = new WorkItemPublic()
            {
                ID                   = 1,
                Description          = Guid.NewGuid().ToString(),
                Name                 = Guid.NewGuid().ToString(),
                WorkItemEnd          = DateTime.Now,
                WorkItemStart        = DateTime.Now,
                WorkItemCollectionID = 1
            };

            dbContext.WorkItems.Add(new WorkItem()
            {
                ID = 1
            });

            dbContext.WorkItemCollections.Add(new WorkItemCollection()
            {
                ID          = 1,
                TaskBoardId = 1
            });

            dbContext.TaskBoards.Add(new TaskBoard()
            {
                ID     = 1,
                UserID = 1
            });

            dbContext.Users.Add(new User()
            {
                ID = 1
            });

            dbContext.SaveChanges();

            // ACT
            WorkItemPublic result = repository.UpdateWorkItem(workItem);

            // ASSERT
            result.Should().BeEquivalentTo <WorkItemPublic>(workItem);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Dodaje pojedynczy WorkItem do Kolekcji, lub aktualizuje jego parametry, jeżeli już istnieje.
        /// </summary>
        /// <param name="workItem"></param>
        public void LoadOrUpdateWorkItem(WorkItemPublic workItem)
        {
            Ensure.ParamNotNull(workItem, nameof(workItem));

            CtrlWorkItemDisplay toUpdate = TaskBoard.FirstOrDefault(tb => ((WorkItemDisplayViewModel)tb.DataContext).WorkItem.ID == workItem.ID);

            if (toUpdate != null)
            {
                WorkItemPublic workItemPublic = ((WorkItemDisplayViewModel)toUpdate.DataContext).WorkItem = workItem;
                ((WorkItemDisplayViewModel)toUpdate.DataContext).UpdateDisplayProperties();
            }
            else
            {
                TaskBoard.Add(new CtrlWorkItemDisplay(workItem, DayOffset, mContext));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Wysyła wiadomość o aktualizacji workitema
        /// </summary>
        public void AddItemToCollection(WorkItemPublic workItem)
        {
            if (CollectionAddItemEvent == null)
            {
                return;
            }

            Ensure.ParamNotNull(workItem, nameof(workItem));

            WorkItemEventArgs wia = new WorkItemEventArgs()
            {
                WorkItem = workItem
            };

            CollectionAddItemEvent(this, wia);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Wysyła wiadomość o aktualizacji workitema
        /// </summary>
        public void UpdateWorkItem(WorkItemPublic workItem)
        {
            if (WorkItemUpdatedEvent == null)
            {
                return;
            }

            Ensure.ParamNotNull(workItem, nameof(workItem));

            WorkItemEventArgs wia = new WorkItemEventArgs()
            {
                WorkItem = workItem
            };

            WorkItemUpdatedEvent(this, wia);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Tworzy WorkItem w bazie danych
        /// </summary>
        /// <returns></returns>
        public async Task <WorkItemPublic> CreateWorkItem()
        {
            try
            {
                HttpWorkItemClient client = new HttpWorkItemClient();

                WorkItemPublic updatedWorkItem = await client.CreateWorkItem(WorkItem).ConfigureAwait(false);

                return(updatedWorkItem);
            }
            catch (Exception)
            {
                mContext.DialogBuilder.ErrorDialog("Work Item couldn't be updated, due to server error.");
                return(null);
            }
        }
Exemplo n.º 13
0
        public IActionResult GetWorkItem(int ID)
        {
            if (ID <= 0)
            {
                return(base.BadRequest("ID have to be grater than 0!"));
            }

            WorkItemPublic workItem = mRepository.GetWorkItem(ID);

            if (workItem == null)
            {
                base.NotFound(workItem);
            }

            return(base.Ok(workItem));
        }
Exemplo n.º 14
0
        public IActionResult UpdateWorkItem([FromBody] WorkItemPublic workItem)
        {
            Ensure.ParamNotNull(workItem, nameof(workItem));

            if (workItem.ID <= 0)
            {
                return(base.BadRequest(workItem));
            }

            WorkItemPublic updatedWorkItem = mRepository.UpdateWorkItem(workItem);

            if (updatedWorkItem == null)
            {
                return(base.NotFound(workItem));
            }

            return(base.Created($"/workitems/{updatedWorkItem.ID}", updatedWorkItem));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Metoda odbierająca komunikat o zmianie stanu WorkItema
        /// </summary>
        public void ReloadWorkItem(WorkItemMediator m, WorkItemEventArgs e)
        {
            Ensure.ParamNotNull(e, nameof(e));

            WorkItemPublic workItem = e.WorkItem;
            DateTime       now      = DateTime.Now.Date;

            foreach (CtrlScheduleCanvas canvas in Schedules)
            {
                if (workItem.WorkItemStart.Date <= now.AddDays(((ScheduleCanvasViewModel)canvas.DataContext).DayOffset) && workItem.WorkItemEnd.Date >= now.AddDays(((ScheduleCanvasViewModel)canvas.DataContext).DayOffset))
                {
                    ((ScheduleCanvasViewModel)canvas.DataContext).LoadOrUpdateWorkItem(workItem);
                }
                else
                {
                    ((ScheduleCanvasViewModel)canvas.DataContext).DeleteWorkItem(workItem);
                }
            }
        }
Exemplo n.º 16
0
        public virtual IActionResult CreateWorkItem([FromBody] WorkItemPublic workItem)
        {
            Ensure.ParamNotNull(workItem, nameof(workItem));

            // workItem musi mieć ustawionego rodzica
            if (workItem.WorkItemCollectionID <= 0)
            {
                return(base.BadRequest(workItem));
            }

            try
            {
                WorkItemPublic workItemPublic = mRepository.CreateWorkItem(workItem);
                return(base.Created($"/workitems/{workItemPublic.ID}", workItemPublic));
            }
            catch
            {
                return(base.BadRequest(workItem));
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Dodaje workItem do kontenera
        /// </summary>
        public void AddWorkItemToContainer(WorkItemMediator m, WorkItemEventArgs e)
        {
            Ensure.ParamNotNull(e, nameof(e));

            WorkItemPublic workItem = e.WorkItem;

            CtrlWorkItemContainer      container = ContainerCollection.FirstOrDefault(cc => ((WorkItemContainerViewModel)cc.DataContext).WorkItemCollection.ID == workItem.WorkItemCollectionID);
            WorkItemContainerViewModel wic       = (WorkItemContainerViewModel)container.DataContext;
            WorkItemPublic             wi        = wic.WorkItems.FirstOrDefault(wi => wi.ID == workItem.ID);

            if (wi == null)
            {
                wic.WorkItems.Add(workItem);
            }
            else
            {
                int index = wic.WorkItems.IndexOf(wi);
                wic.WorkItems.Remove(wi);
                wic.WorkItems.Insert(index, workItem);
            }
        }
Exemplo n.º 18
0
        /// <inheritdoc/>
        public async Task <WorkItemPublic> UpdateWorkItem(WorkItemPublic workItem)
        {
            Ensure.ParamNotNull(workItem, nameof(workItem));

            WorkItemPublic UserResponse = null;

            using (HttpClient httpClient = base.CreateClient())
            {
                string jsonString = JsonConvert.SerializeObject(workItem);
                Uri    postUri    = new Uri(httpClient.BaseAddress, "/workItems/");

                HttpResponseMessage response = await httpClient.PutAsync(postUri, new StringContent(jsonString, Encoding.UTF8, "application/json"));

                if (response.IsSuccessStatusCode)
                {
                    string json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    UserResponse = JsonConvert.DeserializeObject <WorkItemPublic>(json);
                }
            }

            return(UserResponse);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Metoda dodajaca nowe zadanie do obserswowalnej kolekcji zadan
        /// </summary>
        private async Task AddWorkItem()
        {
            try
            {
                HttpWorkItemClient client = new HttpWorkItemClient();

                WorkItemPublic workItem = new WorkItemPublic()
                {
                    Name = "WorkItem",
                    WorkItemCollectionID = WorkItemCollection.ID,
                    WorkItemStart        = DateTime.Now.Date.AddHours(12),
                    WorkItemEnd          = DateTime.Now.Date.AddHours(13)
                };

                await Application.Current.Dispatcher.BeginInvoke(() =>
                {
                    mContext.WindowManager.OpenWindow(new DlgWorkItemDetails(workItem, mContext));
                });
            }
            catch (Exception)
            {
                mContext.DialogBuilder.ErrorDialog("Could not create the Work Item, due to server error.");
            }
        }
Exemplo n.º 20
0
 public DlgWorkItemDetails(WorkItemPublic workItem, ITerminalContext context)
 {
     InitializeComponent();
     this.DataContext = new WorkItemDetailsViewModel(workItem, context);
 }
Exemplo n.º 21
0
        public CtrlWorkItemDisplay(WorkItemPublic workItem, int dayOffset, ITerminalContext context)
        {
            InitializeComponent();

            DataContext = new WorkItemDisplayViewModel(workItem, dayOffset, context);
        }
Exemplo n.º 22
0
 /// <inheritdoc/>
 public WorkItemPublic CreateWorkItem(WorkItemPublic workItem)
 {
     mWorkItems.Add(workItem);
     return(workItem);
 }
Exemplo n.º 23
0
        /// <inheritdoc/>
        public void DeleteWorkItem(int ID)
        {
            WorkItemPublic workItem = this.GetWorkItem(ID);

            mWorkItems.Remove(workItem);
        }
Exemplo n.º 24
0
 /// <inheritdoc/>
 public WorkItemPublic UpdateWorkItem(WorkItemPublic workItem)
 {
     return(workItem);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Pokazuje okno edycji Work Itema z odniesieniem do niego
 /// </summary>
 private void ShowEditDialog(WorkItemPublic workItem)
 {
     mContext.WindowManager.OpenWindow(new DlgWorkItemDetails(workItem, mContext));
 }