Ejemplo n.º 1
0
        public async Task <ActionResult <ToDo> > Post([FromBody] ToDo item)
        {
            var result = await toDoService.Create(item);

            Console.WriteLine("Created");
            return(CreatedAtAction(nameof(Get), new { result.Id }, result));
        }
        public async Task <IActionResult> Create([Bind("Id,Description,CreatedDate")] Todo todo)
        {
            if (ModelState.IsValid)
            {
                await _service.Create(todo);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(todo));
        }
Ejemplo n.º 3
0
        public IActionResult Post(string _id, [FromBody] ToDo value)
        {
            if (!_toDoService.Validate(value))
            {
                return(this.BadRequest());
            }
            var todo = _toDoService.Create(value);

            return(this.Ok(todo));
        }
Ejemplo n.º 4
0
        public async void ShouldCreateToDo()
        {
            // given
            _toDoRepositoryMock.Setup(r => r.GetToDos()).Returns(new[] { toDo1 });
            _toDoRepositoryMock.Setup(r => r.InsertTodo(It.IsAny <ToDo>())).Verifiable();
            // when
            await _toDoService.Create(toDo2);

            // then
            _toDoRepositoryMock.Verify(r => r.InsertTodo(It.IsAny <ToDo>()), Times.Once);
        }
Ejemplo n.º 5
0
 public ActionResult CreateToDo(Entities.Concrete.ToDo entity)
 {
     try
     {
         _toDoService.Create(entity);
         return(Ok());
     }
     catch (Exception)
     {
         return(BadRequest(entity));
     }
 }
Ejemplo n.º 6
0
        public void Create_ExpectVerifyTrue_WhenCallWithNewToDoObjectParaMeter()
        {
            //Arrange
            var Id  = 1;
            var emp = new ToDo {
                Name = "UK"
            };

            _mockRepository.Setup(m => m.Add(emp)).Returns((ToDo e) =>
            {
                e.Id = Id;
                return(e);
            });

            //Act
            _service.Create(emp);

            //Assert
            Assert.Equal(Id, emp.Id);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Post([FromBody] ToDo toDo)
        {
            try
            {
                if (toDo == null)
                {
                    return(BadRequest("Object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                var created = await _toDoService.Create(toDo);

                return(CreatedAtRoute("", new { id = created.Id }, toDo));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(StatusCode(500, "Internal server error"));
            }
        }
Ejemplo n.º 8
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            #region Validation

            if (String.IsNullOrEmpty(CurrentToDo.Name))
            {
                MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Ime_grla"));
                return;
            }

            #endregion

            Thread th = new Thread(() =>
            {
                SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke"));
                SaveButtonEnabled = false;

                CurrentToDo.IsSynced = false;
                CurrentToDo.Company  = new CompanyViewModel()
                {
                    Id = MainWindow.CurrentCompanyId
                };
                CurrentToDo.CreatedBy = new UserViewModel()
                {
                    Id = MainWindow.CurrentUserId
                };


                ToDoResponse response = new ToDoSQLiteRepository().Delete(CurrentToDo.Identifier);
                response = new ToDoSQLiteRepository().Create(CurrentToDo);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_čuvanjaUzvičnik"));
                    SaveButtonContent       = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled       = true;
                    return;
                }

                response = toDoService.Create(CurrentToDo);
                if (!response.Success)
                {
                    MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Podaci_su_sačuvani_u_lokaluUzvičnikTačka_Greška_kod_čuvanja_na_serveruUzvičnik"));
                    SaveButtonContent       = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled       = true;
                }

                if (response.Success)
                {
                    MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik"));
                    SaveButtonContent         = ((string)Application.Current.FindResource("Sačuvaj"));
                    SaveButtonEnabled         = true;

                    ToDoCreatedUpdated();

                    if (IsCreateProcess)
                    {
                        CurrentToDo            = new ToDoViewModel();
                        CurrentToDo.Identifier = Guid.NewGuid();
                        CurrentToDo.ToDoDate   = DateTime.Now;
                        CurrentToDo.IsPrivate  = IsPrivate;

                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            txtName.Focus();
                        })
                            );
                    }
                    else
                    {
                        Application.Current.Dispatcher.BeginInvoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(() =>
                        {
                            if (IsPopup)
                            {
                                FlyoutHelper.CloseFlyoutPopup(this);
                            }
                            else
                            {
                                FlyoutHelper.CloseFlyout(this);
                            }
                        })
                            );
                    }
                }
            });
            th.IsBackground = true;
            th.Start();
            txtName.Focus();
        }
 public ToDo Post([FromBody] ToDo model)
 {
     service.Create(model);
     service.Save();
     return(model);
 }
Ejemplo n.º 10
0
        public async Task <ActionResult <ToDo> > PostTodos([FromBody] ToDo toDo)
        {
            var newToDo = await _toDoService.Create(toDo);

            return(CreatedAtAction(nameof(GetTodos), new { Id = newToDo.Id }, newToDo));
        }