Exemple #1
0
        public async Task <ActionResult <ToDoItem> > UpdateTask(int id, ToDoItemDto toDoItemDto)
        {
            if (ModelState.IsValid)
            {
                var toDoItem = await _toDoContext.ToDoItems.FindAsync(id);

                if (toDoItem != null)
                {
                    toDoItem.DueDate  = toDoItemDto.DueDate;
                    toDoItem.Label    = toDoItemDto.Label;
                    toDoItem.Status   = toDoItemDto.Status;
                    toDoItem.ToDo     = toDoItemDto.ToDo;
                    toDoItem.DueDate  = toDoItemDto.DueDate;
                    toDoItem.UpdateDt = DateTime.UtcNow;
                    _toDoContext.Attach(toDoItem);
                    _toDoContext.Entry(toDoItem).State = EntityState.Modified;
                    var output = await _toDoContext.SaveChangesAsync();

                    if (output > 0)
                    {
                        return(Ok(toDoItem));
                    }
                }
                return(BadRequest("Item not found"));
            }

            return(BadRequest("Some error happened"));
        }
Exemple #2
0
        // akcija za izmenu podataka entiteta
        protected virtual IActionResult Izmena(long id, Tdto entitetDTO)
        {
            T entitet = _DbSet.Find(id);

            if (entitet == null)
            {
                return(BadRequest("Ne mogu naci entitet koji menjas"));
            }
            T   map = _mapper.Map <Tdto, T>(entitetDTO, entitet);
            var ww  = _context.Attach(map).Entity;

            _context.SaveChanges();

            return(Ok("Vase izmene su sacuvane!"));
        }