public static Model.Response.CodeResponse Sync() { Model.Response.CodeResponse response = new Model.Response.CodeResponse(); try { response = SyncBooks(); if (!ValidateResponse(response)) { return(response); } response = SyncAuthors(); if (!ValidateResponse(response)) { return(response); } response.code = 100; response.message = "Success"; } catch (Exception ex) { response.code = 500; response.message = ex.Message; } return(response); }
private static Model.Response.CodeResponse SyncAuthors() { string urlApiIngeneo = Data.Util.ConfigReader.GetValue("urlApiIngeneo"); string methodAuthor = Data.Util.ConfigReader.GetValue("methodSyncAuthors"); Model.Response.CodeResponse response = new Model.Response.CodeResponse(); try { string urlComplete = urlApiIngeneo + methodAuthor; string typeMethod = "GET"; string json = string.Empty; string answer = Util.SendRequestAPI.Request(urlComplete, typeMethod, json); List <Model.Entities.AuthorEntity> listAuthors = new List <Model.Entities.AuthorEntity>(); listAuthors = JsonConvert.DeserializeObject <List <Model.Entities.AuthorEntity> >(answer); foreach (Model.Entities.AuthorEntity author in listAuthors) { response = Data.AuthorData.Create(author); if (!ValidateResponse(response)) { return(response); } } } catch (Exception ex) { response.code = 500; response.message = ex.Message; } return(response); }
private static bool ValidateResponse(Model.Response.CodeResponse response) { if (!string.IsNullOrEmpty(response.message)) { return(false); } return(true); }
private static bool ValidateRequest(Model.Request.BookRequest request) { Model.Response.CodeResponse codeResponse = new Model.Response.CodeResponse(); if (request.idBook < 0) { codeResponse.code = 101; codeResponse.message = "ID Number invalid"; return(false); } return(true); }
private static bool ValidateRequest(Model.Request.LoginRequest request) { Model.Response.CodeResponse codeResponse = new Model.Response.CodeResponse(); if (string.IsNullOrEmpty(request.email)) { codeResponse.code = 101; codeResponse.message = "Email invalid"; return(false); } if (string.IsNullOrEmpty(request.password)) { codeResponse.code = 102; codeResponse.message = "Password invalid"; return(false); } return(true); }
public ActionResult <Model.Response.CodeResponse> SyncWithIngeneoApi() { Model.Response.CodeResponse response = Business.SyncBusiness.Sync(); return(response); }