public IHttpActionResult Add(RSAddDto rs) { try { var result = _rsBL.Save(rs); return(Ok(result)); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } }
public RSModel Save(RSAddDto rs) { // INPUT VALIDATION rs.Empty().Throw("DATA RUMAH SAKIT empty"); rs.Empty().Throw("RUMAH SAKIT kosong"); rs.RSID.Empty().Throw("RUMAH SAKIT ID invalid"); rs.RSID.Length.GreaterThan(5).Throw("RUMAH SAKIT ID max length is 5"); rs.RSName.Empty().Throw("RUMAH SAKIT NAME empty"); rs.RSName.Length.GreaterThan(30).Throw("RUMAH SAKIT NAME max length is 30"); rs.KotaID.Empty().Throw("KOTA ID empty"); // CONSTRUCT MODEL var result = new RSModel { RSID = rs.RSID, RSName = rs.RSName, KotaID = rs.KotaID }; // BUSINESS VALIDATION var kt = _kotaDal.GetData(result); kt.Empty().Throw("KOTA ID invalid"); result.KotaName = kt.KotaName; // APPLY var exist = _rsDal.GetData(result); if (exist != null) { _rsDal.Update(result); } else { _rsDal.Insert(result); } // RETURN return(result); }
private void Validate(RSAddDto rs) { }