public IActionResult Get(int id) { var repo = this.Storage.GetRepository <IWorkPlacementRepository>(); WorkPlacement work = repo.WithKey(id); if (work == null) { return(this.NotFound(new { success = false })); } return(Ok(new { success = true, data = work })); }
public IActionResult Post(WorkPlacementCreateViewModel model) { if (this.ModelState.IsValid) { WorkPlacement work = model.ToWorkEntity(); var repo = this.Storage.GetRepository <IWorkPlacementRepository>(); repo.Create(work, GetCurrentUserName()); this.Storage.Save(); return(Ok(new { success = true, data = work })); } return(BadRequest(new { success = false })); }
public IActionResult Delete(int id) { var repo = this.Storage.GetRepository <IWorkPlacementRepository>(); WorkPlacement work = repo.WithKey(id); if (work == null) { return(this.NotFound(new { success = false })); } repo.Delete(work, GetCurrentUserName()); this.Storage.Save(); return(Ok(new { success = "Data berhasil dihapus" })); }
public IActionResult Put(int id, WorkPlacementUpdateViewModel model) { var repo = this.Storage.GetRepository <IWorkPlacementRepository>(); WorkPlacement work = repo.WithKey(id); if (work == null) { return(this.NotFound(new { success = false })); } if (this.ModelState.IsValid) { model.ToWorkEntity(work); repo.Edit(work, GetCurrentUserName()); this.Storage.Save(); return(Ok(new { success = "Data berhasil diperbaharui" })); } return(BadRequest(new { success = false })); }