public static MatTranTypes RegisterMatTransType(MatTranTypes matTranTypes) { try { using Repository <MatTranTypes> repo = new Repository <MatTranTypes>(); matTranTypes.AddDate = DateTime.Now; var record = repo.MatTranTypes.OrderByDescending(x => x.AddDate).FirstOrDefault(); if (record != null) { matTranTypes.Code = CommonHelper.IncreaseCode(record.Code); } else { matTranTypes.Code = "1"; } repo.MatTranTypes.Add(matTranTypes); if (repo.SaveChanges() > 0) { return(matTranTypes); } return(null); } catch { throw; } }
public IActionResult RegisterMatTransType([FromBody] MatTranTypes mattrantypes) { if (mattrantypes == null) { return(Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = $"{nameof(mattrantypes)} cannot be null" })); } try { var response = BillingHelpers.RegisterMatTransType(mattrantypes); if (response != null) { return(Ok(new APIResponse() { status = APIStatus.PASS.ToString(), response = response })); } return(Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = " Registration Failed." })); } catch (Exception ex) { return(Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = ex.Message })); } }
public static MatTranTypes UpdateMatTransType(MatTranTypes matTranTypes) { try { using Repository <MatTranTypes> repo = new Repository <MatTranTypes>(); repo.MatTranTypes.Update(matTranTypes); if (repo.SaveChanges() > 0) { return(matTranTypes); } return(null); } catch { throw; } }