public OperationResponse <bool> Post(EditDeclaration editDeclaration) { OperationResponse <bool> response = new OperationResponse <bool>(); try { var newDeclaration = editDeclaration.Declaration; DeclarationValidator obj = new DeclarationValidator(); ValidationResult result = obj.Validate(newDeclaration); if (result.IsValid) { var data = DeclarationBll.EditDeclaration(newDeclaration); ReferenceDto reference = new ReferenceDto(); for (int i = 0; i < editDeclaration.ReferenceData.Length; i++) { reference.DeclarationId = newDeclaration.DeclarationId; reference.ReferenceId = editDeclaration.ReferenceData[i].ReferenceId; reference.InvoiceDate = editDeclaration.ReferenceData[i].InvoiceDate; reference.Reference = editDeclaration.ReferenceData[i].Reference; reference.Type = editDeclaration.ReferenceData[i].Type; DeclarationBll.AddReference(reference); } response.OnSuccess(data, "Record Successfully Updated"); return(response); } else { List <string> errors = new List <string>(); foreach (var err in result.Errors) { errors.Add(err.ErrorMessage); } response.OnError("one or more validations failed", errors); return(response); } } catch (Exception e) { Log.Error(e.Message + " " + e.StackTrace); response.OnException("Error in updating record"); return(response); } }
public OperationResponse <bool> Post(AddDeclaration newDeclaration) { OperationResponse <bool> response = new OperationResponse <bool>(); try { var declaration = newDeclaration.Declaration; DeclarationValidator obj = new DeclarationValidator(); ValidationResult result = obj.Validate(declaration); if (result.IsValid) { var data = DeclarationBll.AddDeclaration(declaration); var id = data; ReferenceDto reference = new ReferenceDto(); for (int i = 0; i < newDeclaration.ReferenceData.Length; i++) { reference.DeclarationId = data; reference.InvoiceDate = newDeclaration.ReferenceData[i].InvoiceDate; reference.Reference = newDeclaration.ReferenceData[i].Reference; reference.Type = newDeclaration.ReferenceData[i].Type; DeclarationBll.AddReference(reference); } response.OnSuccess(true, "Declaration Successfully added!"); return(response); } else { List <string> error = new List <string>(); foreach (var err in result.Errors) { error.Add(err.ErrorMessage); } response.OnError("One or more validations failed", error); return(response); } } catch (Exception e) { Log.Error(e.Message + " " + e.StackTrace); response.OnException("Request to Add new declaration failed at server side."); return(response); } }