public async Task <int> AddBranchUnit(BranchUnit entity) { var unit = await this._context.Units.FirstOrDefaultAsync(m => m.Kode == entity.UnitKode); unit.CabangUnits.Add(entity); return(await this._context.SaveChangesAsync()); }
public async Task <IActionResult> AddUnitUnit([FromBody] BranchUnit entity) { try { var t = await this._unitService.AddBranchUnit(entity); var res = new CustomResponse() { errors = null, message = "Tambah Unit Berhasil", title = "Success", ok = true }; if (t == 1) { return(Ok(res)); } res = new CustomResponse() { errors = null, message = "Tambah Unit Gagal", title = "Warning", ok = false }; return(BadRequest(res)); } catch (Exception ex) { var res = new CustomResponse() { errors = new List <string>() { ex.InnerException.Message }, message = ex.Message, title = "Error", ok = false }; return(BadRequest(res)); } }