public IActionResult Post([FromBody] TimesheetModel timesheet) { try { _timesheetService.Add(timesheet.ToDomainModel()); } catch (System.Exception ex) { ModelState.AddModelError("AddTimesheet", ex.Message); return(BadRequest(ModelState)); } return(CreatedAtAction("Get", new { Id = timesheet.Id }, timesheet)); }
public IActionResult Post(int profileId, [FromBody] TimesheetModel timesheetModel) { try { var timesheet = timesheetModel.ToDomainModel(); _timesheetService.Add(timesheet); return(Ok(timesheet)); } catch (Exception ex) { ModelState.AddModelError("AddTimesheet", ex.Message); return(BadRequest(ModelState)); } }
public async Task <ActionResult <TimesheetViewModel> > PostTimesheet(TimesheetViewModel timesheet) { if (timesheet != null) { try { await Task.Run(() => { timesheet.DateCreated = DateTime.Now; _timesheetService.Add(timesheet); _timesheetService.SaveChanges(); return(Ok("Thêm thành công!")); }); } catch { throw new Exception(string.Format("Lỗi khi thêm dữ liệu")); } } return(CreatedAtAction("GetLecturer()", new { id = timesheet.Id }, timesheet)); }