public IdBug Post(string date, string status, string whoReported) { var bug = new Bug { Status = status, Id = 0 }; char[] charsToTrim = { '\\', '\"' }; date = date.Trim(charsToTrim); bug.Date = Convert.ToDateTime(date); bug.WhoReported = whoReported; _db.Bugs.Add(bug); _db.SaveChanges(); return new IdBug {Id = bug.Id}; }
public IdBug Put(string status, string date, string whoReported, int id = 0) { var idBug = 0; if (id != 0) { var bug = _db.Bugs.ToList().Find(e => e.Id == id); bug.Status = status; char[] charsToTrim = { '\\', '\"' }; date = date.Trim(charsToTrim); bug.Date = Convert.ToDateTime(date); bug.WhoReported = whoReported; _db.SaveChanges(); idBug = bug.Id; } else { var bug = new Bug { Status = status, Id = 0 }; char[] charsToTrim = { '\\', '\"' }; date = date.Trim(charsToTrim); bug.Date = Convert.ToDateTime(date); bug.WhoReported = whoReported; _db.Bugs.Add(bug); _db.SaveChanges(); idBug = bug.Id; } return new IdBug{Id=idBug}; }