public async Task <TODOEntity> Add(TODOEntity tODOEntity) { var tODOList = LoadDatabase(); tODOEntity.Id = ReturnNextId(tODOList); tODOList.Add(tODOEntity); SaveDatabase(tODOList); return(tODOEntity); }
public void Update(TODOEntity e) { TODOEntity u = List.Where(x => x.ID == e.ID).Single(); u.Name = e.Name; u.Status = e.Status; u.Description = e.Description; Save(); }
public void Read() { using (StreamReader sr = new StreamReader(Path)) { while (!sr.EndOfStream) { List.Add(TODOEntity.FromString(sr.ReadLine())); } } }
public async Task <IActionResult> AddAsync([FromBody] TODOCreate tODOCreate) { try { TODOEntity tODOEntity = _mapper.Map <TODOEntity>(tODOCreate); await _serviceTODO.Add(tODOEntity); TODODetail tODOResult = _mapper.Map <TODODetail>(tODOEntity); return(Ok(tODOResult)); } catch (Exception ex) { return(BadRequest("Failed to add a TODO")); } }
public async Task <TODOEntity> Update(TODOEntity tODOEntity) { var tODOList = LoadDatabase(); foreach (var tODO in tODOList) { if (tODOEntity.Id == tODO.Id) { tODO.Update(tODOEntity); SaveDatabase(tODOList); return(tODOEntity); } } return(null); }
public async Task <IActionResult> UpdateAsync([FromBody] TODODetail tODODetail) { try { TODOEntity tODOEntity = _mapper.Map <TODOEntity>(tODODetail); tODOEntity = await _serviceTODO.Update(tODOEntity); if (tODOEntity == null) { return(BadRequest("TODO not found")); } TODODetail tODOResult = _mapper.Map <TODODetail>(tODOEntity); return(Ok(tODOResult)); } catch (Exception ex) { return(BadRequest("Failed to update a TODO")); } }
public async Task <TODOEntity> Update(TODOEntity tODOEntity) { return(await _repositoryTODO.Update(tODOEntity)); }
public async Task <TODOEntity> Add(TODOEntity tODOEntity) { return(await _repositoryTODO.Add(tODOEntity)); }
public void Remove(TODOEntity e) { List.Remove(e); Save(); }
public void Add(TODOEntity entity) { Add(entity.Name, entity.Status, entity.Description); }
public async Task <TODOEntity> Update(TODOEntity tODOEntity) { tODOEntity.UpdatedAt = DateTime.Now; return(await _database.Update(tODOEntity)); }
public async Task <TODOEntity> Add(TODOEntity tODOEntity) { tODOEntity.CreatedAt = DateTime.Now; return(await _database.Add(tODOEntity)); }
static void Main(string[] args) { Menu menu = new Menu(() => { if (list != null) { Console.WriteLine("=> Working with file: " + list.Path + "\r\n"); } return("\r\n"); }); menu.Add("create", "Create new todo file", () => { Console.WriteLine("Name:"); list = TODOList.Create(Console.ReadLine()); return("\r\nTODO File created\r\n"); }); menu.Add("add", "Create new todo in list", () => { OpenList().Add(NewEntityDialog()); OpenList().Save(); return("\r\nTask successfully saved\r\n"); }); menu.Add("show", "Print todo with id", () => { try { Console.WriteLine(EntityById(OpenList()).ToString()); return("\r\nTask successfully printed\r\n"); } catch (Exception e) { Console.WriteLine(e); return("\r\nFail"); } }); menu.Add("edit", "Edit todo with id", () => { try { TODOList l = OpenList(); TODOEntity e = EntityById(l); Console.WriteLine(e.ToString()); TODOEntity newEntity = NewEntityDialog(); newEntity.ID = e.ID; l.Update(newEntity); l.Save(); return("\r\nTask successfully updated\r\n"); } catch (Exception e) { Console.WriteLine(e); return("Fail"); } }); menu.Add("remove", "Remove todo with id from list", () => { try { TODOList l = OpenList(); TODOEntity e = EntityById(l); Console.WriteLine(e.ToString()); l.Remove(e); return("\r\nSuccessfully removed"); } catch (Exception e) { Console.WriteLine(e); return("\r\nFail"); } }); menu.Add("showall", "Show all todos", () => { try { OpenList().Print(); Console.WriteLine("\r\nPress enter to return to the menu."); Console.Read(); return("\r\nSuccessfully printed all todos\r\n"); } catch (Exception e) { Console.WriteLine(e); return("\r\nFail"); } }); menu.Start(); }