Example #1
0
        public async Task <ActionResult> Create(TodoList item)
        {
            if (ModelState.IsValid)
            {
                context.Add(item);
                await context.SaveChangesAsync();

                TempData["Success"] = "The item has been added!";
                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] TodoItem item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _context.Items.AddAsync(item);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetTodoItem", new { id = item.Id }));
        }
Example #3
0
        public async Task <IActionResult> PutTodoItem(long id, TodoItem item)
        {
            if (id != item.id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Example #4
0
        public async Task <IHttpActionResult> PostTodoItem(TodoItemDTO todoItemDTO)
        {
            var todoItem = new TodoItem
            {
                IsComplete = todoItemDTO.IsComplete,
                Name       = todoItemDTO.Name
            };

            _context.TodoItems.Add(todoItem);
            await _context.SaveChangesAsync();

            return(Ok(ItemToDTO(todoItem)));
        }
Example #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] TodoItem todoItem, string[] selectedTags)
        {
            if (!ModelState.IsValid)
            {
                return(View(todoItem));
            }

            UpdateTodoTags(selectedTags, todoItem);
            _context.Add(todoItem);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <ActionResult> Put(long id, Usuario usuario)
        {
            if (id != usuario.Id)
            {
                return(BadRequest());
            }

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

            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> DeleteTodoItem(long id)
        {
            var todoItem = await _context.TodoItems.FindAsync(id);

            if (todoItem == null)
            {
                return(NotFound());
            }
            _context.TodoItems.Remove(todoItem);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("Title,Description,DueDate")] TodoItem todo)
        {
            if (ModelState.IsValid)
            {
                todo.DoneDate = DateTime.Now;
                todo.Done     = false;
                _context.Add(todo);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(View(todo));
        }
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItemDto todoItemDto)
        {
            var todoItem = new TodoItem {
                IsComplete = todoItemDto.IsComplete,
                Name       = todoItemDto.Name,
                IsDelete   = false
            };

            _context.TodoItems.Add(todoItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, ConvertItemToDTO(todoItem)));
        }
Example #10
0
        public async Task <IActionResult> Post([FromBody] ToDoItem item)
        {
            if (!ModelState.IsValid)//se encarga de validar los parametros que se pasan al metodo
            {
                return(BadRequest(ModelState));
            }

            _context.Items.Add(item);
            await _context.SaveChangesAsync();

            //return Ok(item);
            return(CreatedAtRoute("GetToDoItem", new { id = item.Id }, item));//es la forma mas estandar de hacer la api
        }
Example #11
0
        public async Task UpdateTodoItem(long id, TodoItem newTodoItem)
        {
            var oldTodoItem = await _context.TodoItems.FindAsync(id);

            if (oldTodoItem == null)
            {
                return;
            }

            oldTodoItem.Name       = newTodoItem.Name;
            oldTodoItem.IsComplete = newTodoItem.IsComplete;
            await _context.SaveChangesAsync();
        }
Example #12
0
        public async Task <IActionResult> Create([FromBody] TodoItem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            await _context.TodoItems.AddAsync(item);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("GetTodo", new { id = item.Id }, item));
        }
Example #13
0
        public async Task <ActionResult <TodoItem> > CreateTodoItem(TodoItem item)
        {
            try {
                _context.TodoItems.Add(item);
                await _context.SaveChangesAsync();
            }
            catch (ArgumentException)
            {
                return(Conflict());
            }

            return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item));
        }
Example #14
0
        public async Task <IActionResult> PostTodoItem([FromBody] TodoItem todoItem, [FromRoute] int listid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            todoItem.TodoListId = listid;
            _context.TodoItem.Add(todoItem);
            await _context.SaveChangesAsync();

            return(Ok(todoItem));
            //return CreatedAtAction("GetTodoItem", new { id = todoItem.id }, todoItem);
        }
Example #15
0
        public async Task <IActionResult> PutCandidat(string id, Candidat candidat)
        {
            Candidat user = (Candidat)await userManager.FindByIdAsync(id);

            if (user != null)
            {
                user.nom                   = candidat.nom;
                user.prenom                = candidat.prenom;
                user.adresse               = candidat.adresse;
                user.date_naissance        = candidat.date_naissance;
                user.PhoneNumber           = candidat.PhoneNumber;
                user.etat_matrimonial      = candidat.etat_matrimonial;
                user.genre                 = candidat.genre;
                user.metier                = candidat.metier;
                _context.Entry(user).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(Ok(new
                {
                    user
                }));
            }
            return(BadRequest());

            /* if (id != candidat.Id)
             * {
             *   return BadRequest();
             * }
             *
             * _context.Entry(candidat).State = EntityState.Modified;
             *
             * try
             * {
             *   await _context.SaveChangesAsync();
             * }
             * catch (DbUpdateConcurrencyException)
             * {
             *   if (!CandidatExists(id))
             *   {
             *       return NotFound();
             *   }
             *   else
             *   {
             *       throw;
             *   }
             * }
             *
             * return Ok(new {
             *   candidat
             * });*/
        }
        public async Task <IActionResult> FlipComplete(int id)
        {
            var todo = _context.Todos.SingleOrDefault(t => t.Id == id);

            if (todo == null)
            {
                return(NotFound("Todo not found!"));
            }

            todo.Complete = !todo.Complete;
            await _context.SaveChangesAsync();

            return(Ok());
        }
Example #17
0
        public async Task <ActionResult <TodoItem> > AddTodo([FromBody] TodoItem todoItem)
        {
            var itemTodo = new TodoItem
            {
                IsComplete = todoItem.IsComplete,
                Name       = todoItem.Name
            };

            _todoDbContext.TodoItems.Add(itemTodo);

            await _todoDbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(AddTodo), new { id = itemTodo.Id }, ItemTo(itemTodo)));
        }
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem item)
        {
            try
            {
                _context.TodoItems.Add(item);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetTodoItem", new { id = item.Id }, item));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #19
0
        public async Task <ActionResult <Korisnik> > DeleteKorisnik(long id)
        {
            var korisnik = await _context.Korisnici.FindAsync(id);

            if (korisnik == null)
            {
                return(NotFound());
            }

            _context.Korisnici.Remove(korisnik);
            await _context.SaveChangesAsync();

            return(korisnik);
        }
Example #20
0
        public async Task <IActionResult> Post([FromForm] UploadFile objectfile)
        {
            try

            {
                if (objectfile.file.Length > 0)
                {
                    string path = _webHostEnvironment.WebRootPath + "\\uploads\\";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    //string.Format(@"{0}.txt", Guid.NewGuid())
                    string nnn = Path.GetFileNameWithoutExtension(objectfile.file.FileName);
                    nnn = string.Format(@"{0}.pdf", Guid.NewGuid());
                    var sss     = Path.GetExtension(objectfile.file.FileName);
                    var newname = string.Format(@"{0}.pdf", Guid.NewGuid());
                    using (FileStream fileStream = System.IO.File.Create(path + newname))
                    {
                        objectfile.file.CopyTo(fileStream);
                        fileStream.Flush();
                        var user = await userManager.FindByIdAsync(objectfile.useremail);

                        Console.WriteLine("aaaaaaaaaa!!!!!!!!!!!!!!!!!!!!!!!!!!" + user.nom);
                        user.CVname                = newname;
                        user.CVoriginalfilename    = objectfile.file.FileName;
                        _context.Entry(user).State = EntityState.Modified;
                        await _context.SaveChangesAsync();

                        return(Ok(new Response
                        {
                            message = "File uploaded !",
                            status = newname,
                            extrafield = objectfile.file.FileName
                        }));
                    }
                }
                else
                {
                    return(Ok(new Response
                    {
                        message = "you have to choose a file first !"
                    }));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Example #21
0
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem item)
        {
            if (!string.IsNullOrEmpty(item.Nome))
            {
                _context.TodoItems.Add(item);
                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item));
            }
            else
            {
                return(NotFound("teste"));
            }
        }
Example #22
0
        public async Task <IActionResult> Delete(int id)
        {
            var entity = await _repository.TodoItems.SingleOrDefaultAsync(x => x.Id == id);

            if (entity == null)
            {
                return(Ok(0));
            }

            _repository.TodoItems.Remove(entity);
            await _repository.SaveChangesAsync();

            return(Ok());
        }
Example #23
0
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem item)
        {
            try
            {
                _context.TodoItems.Add(item);
                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #24
0
        public async Task <TodoItem> Create(TodoItem todoItem)
        {
            try
            {
                _context.TodoItems.Add(todoItem);
                var res = await _context.SaveChangesAsync();

                return(todoItem);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to create new Todo!", ex);
            }
        }
Example #25
0
        public async Task <IActionResult> PutUser(UserDTO user)
        {
            int  id        = IdUserAuthenticate();
            User userAtual = _context.Users
                             .Where(u => u.Id == id)
                             .First();

            userAtual.Username = user.Username;
            userAtual.Password = user.Password;

            await _context.SaveChangesAsync();

            return(NoContent());
        }
Example #26
0
        public async Task <Todo> CreateTodo(TodoDto data)
        {
            var todo = new Todo
            {
                Description = data.Description,
                CreatedAt   = DateTime.Now,
            };

            await _context.Todos.AddAsync(todo);

            await _context.SaveChangesAsync();

            return(todo);
        }
Example #27
0
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem item, string userId)
        {
            var user = await _context.Users.FindAsync(userId);

            if (user != null)
            {
                item.UserId = userId;
                _context.TodoItems.Add(item);
                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item));
            }
            return(NotFound());
        }
Example #28
0
        public async Task <ActionResult <Offre> > PostOffre(Offre offre)
        {
            if (await _context.Offre.FindAsync(offre.id) == null)
            {
                offre.archiver = false;
                _context.Offre.Add(offre);
                await _context.SaveChangesAsync();

                return(Ok(new
                {
                    offre
                }));
            }
            return(NotFound());
        }
        public async Task <IActionResult> PostTodoList([FromBody] TodoList todoList, [FromRoute] int accountid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            todoList.AccountId = accountid;
            _context.TodoList.Add(todoList);

            await _context.SaveChangesAsync();

            return(Ok(todoList));
            //  return CreatedAtAction("GetTodoList", new { id = todoList.id }, todoList);
        }
        public async Task <IActionResult> Create(Todo todo)
        {
            try
            {
                var createdEntity = _context.Entry(todo);
                createdEntity.State = EntityState.Added;
                await _context.SaveChangesAsync();

                return(Ok(todo));
            }
            catch (System.Exception)
            {
                return(NotFound());
            }
        }