public async Task <PlannerItemModel> Execute(PlannerItemCreateEditModel model) { var plannerItem = mapper.Map <PlannerItem>(model); await plannerItemRepository.AddAsync(plannerItem); return(mapper.Map <PlannerItemModel>(plannerItem)); }
public async Task <PlannerItemModel> Execute(int id, PlannerItemCreateEditModel editModel) { var item = await plannerItemRepository.GetByIdAsync(id); if (item == null) { throw new ArgumentException("ID does not exist", nameof(id)); } mapper.Map(editModel, item); await plannerItemRepository.UpdateAsync(item); return(mapper.Map <PlannerItemModel>(item)); }
public async Task <IActionResult> EditItem(int id, [FromBody] PlannerItemCreateEditModel editModel) { PlannerItemModel item; try { item = await editPlannerItemCommand.Execute(id, editModel); } catch (ArgumentException) { return(BadRequest()); } return(Ok(item)); }
protected void EditItem(PlannerItemModel item) { var editItem = new PlannerItemCreateEditModel { ID = item.ID, Description = item.Description, CategoryID = item.CategoryID, CompletionDate = item.CompletionDate?.LocalDateTime, PlannedActionDate = item.PlannedActionDate.LocalDateTime, PlannedEndTime = item.PlannedEndTime.LocalDateTime }; PlannerItemComponentService.ShowAddEditModal(Mapper.Map <PlannerItemCreateEditModel>(item), UpdateItem); }
public async Task <PlannerItemModel> AddItem(PlannerItemCreateEditModel plannerItem) { PlannerItemModel createdItem; var client = await GetClient(); try { createdItem = await client.PostJsonAsync <PlannerItemModel>("/api/PlannerItems", plannerItem); } catch { createdItem = null; } return(createdItem); }
public void ShowAddEditModal(PlannerItemCreateEditModel item, Action <PlannerItemModel> onSave) { onSaveCallback = onSave; var modalBody = new RenderFragment(builder => { builder.OpenElement(0, "aside"); builder.AddAttribute(0, "class", "box"); builder.AddAttribute(1, "style", "overflow-y: auto"); builder.OpenComponent <PlannerItemForm>(1); builder.AddAttribute(1, "Item", item); builder.AddAttribute(2, "OnItemSaveCallback", EventCallback.Factory.Create <PlannerItemModel>(this, CloseAddEditModal)); builder.CloseComponent(); builder.CloseElement(); }); modalService.Show(new ModalParams(modalBody, style: ModalStyle.Normal, modalClass: "is-fullscreen-mobile")); }
protected void AddItem(MouseEventArgs e) { var columnBounds = DOMService.GetBoundingClientRect(ColumnEl); // for every 80px from top, time +=1 hour from midnight var clickYRelativeToColumn = e.ClientY - columnBounds.Top; var clickedTime = clickYRelativeToColumn / 80; var clickedHour = Math.Truncate(clickedTime); var partialMinutesClicked = clickedTime - clickedHour; // if user clicks near the middle of the hour, use 30 minute as start. Otherwise use start of hour var clickedMinute = partialMinutesClicked > .4 ? 30 : 0; var startOfInterval = new DateTime(Date.Year, Date.Month, Date.Day, (int)clickedHour, clickedMinute, 0); var item = new PlannerItemCreateEditModel { PlannedActionDate = startOfInterval, PlannedEndTime = startOfInterval.AddHours(1) }; PlannerItemComponentService.ShowAddEditModal(item, UpdateItem); }
protected void EditItem(PlannerItemModel item) { var editItem = new PlannerItemCreateEditModel { CategoryID = item.CategoryID, CompletionDate = item.CompletionDate?.LocalDateTime, Description = item.Description, ID = item.ID, PlannedActionDate = item.PlannedActionDate.LocalDateTime, PlannedEndTime = item.PlannedEndTime.LocalDateTime }; PlannerItemComponentService.ShowAddEditModal(editItem, (PlannerItemModel savedItem) => { OverdueItems.Remove(item); if (!savedItem.CompletionDate.HasValue) { OverdueItems.Add(savedItem); } StateHasChanged(); }); }
public PlannerItemsControllerTestFixture() { fixture = TestFixture.Create(); itemModel = fixture.Create <PlannerItemModel>(); createEditModel = fixture.Create <PlannerItemCreateEditModel>(); var items = new List <PlannerItemModel> { itemModel }; getPlannerItemsByDateQueryMock = fixture.Freeze <Mock <IGetPlannerItemsByDateQuery> >(); getPlannerItemsByDateQueryMock .Setup(m => m.Execute(It.IsAny <DateTime>(), It.IsAny <DateTime>())) .ReturnsAsync(items); getCompletedItemsQueryMock = fixture.Freeze <Mock <IGetCompletedItemsQuery> >(); getCompletedItemsQueryMock .Setup(m => m.Execute()) .ReturnsAsync(items); getOverdueItemsQueryMock = fixture.Freeze <Mock <IGetOverdueItemsQuery> >(); getOverdueItemsQueryMock .Setup(m => m.Execute()) .ReturnsAsync(items); plannerItemRepositoryMock = fixture.Freeze <Mock <IRepository <PlannerItem> > >(); fixture.Freeze <Mock <IMapper> >() .Setup(m => m.Map <PlannerItemCreateEditModel>(It.IsAny <PlannerItem>())) .Returns(createEditModel); createPlannerItemCommandMock = fixture.Freeze <Mock <ICreatePlannerItemCommand> >(); createPlannerItemCommandMock.Setup(m => m.Execute(createEditModel)) .ReturnsAsync(itemModel); editPlannerItemCommandMock = fixture.Freeze <Mock <IEditPlannerItemCommand> >(); }
public EditPlannerItemCommandShould() { this.fixture = new PlannerItemsTestFixture(); sut = fixture.Create <EditPlannerItemCommand>(); editModel = fixture.Create <PlannerItemCreateEditModel>(); }
public async Task <IActionResult> AddNewItem([FromBody] PlannerItemCreateEditModel plannerItemDTO) { var plannerItem = await createPlannerItemCommand.Execute(plannerItemDTO); return(CreatedAtAction(nameof(GetByID), new { id = plannerItem.ID }, plannerItem)); }
public async Task <PlannerItemModel> EditItem(PlannerItemCreateEditModel plannerItem) { var client = await GetClient(); return(await client.PutJsonAsync <PlannerItemModel>($"/api/PlannerItems/{plannerItem.ID}", plannerItem)); }