public ActionResult <Response> PatchItems(TransceivalExchange clientPatchRequestObj) { Response response = _dynamicData.PatchItems(clientPatchRequestObj); if (response.IsResponseSuccess) { return(Ok(new { Result = "Saved", Response = response })); } else { return(Ok(new { Result = response.Message, Response = response })); } }
public Response PatchItems(TransceivalExchange clientPatchRequestObj) { Response responseObj = new Response(); try { string tableName = clientPatchRequestObj.TableName.ToString(); string schemaType = clientPatchRequestObj.Type != null?clientPatchRequestObj.Type.ToString() : string.Empty; var schema = GetTableSchema(tableName, schemaType); var newItemList = clientPatchRequestObj.List.Where(obj => obj.FormType == "NEW").Select(s => s.Data).ToList(); var editItemList = clientPatchRequestObj.List.Where(obj => obj.FormType == "EDIT").Select(s => s.Data).ToList(); var identityColumn = schema.Where(s => s.IsIdentity == true).FirstOrDefault(); bool isResponseValid = true; string inValidResponseTxt = string.Empty; TransceivalExchange transExchnageObj = new TransceivalExchange() { TableName = tableName, IdentityColumnName = identityColumn.ColumnName, Type = schemaType, List = new List <List>(), }; if (identityColumn != null) { if (newItemList.Count > 0) { responseObj = InsertItemInDB(new NewRow() { TableName = tableName, SchemaType = schemaType, IdentityColumnName = identityColumn.ColumnName, dynamicListItems = newItemList, TableSchemaList = schema }); if (responseObj.IsResponseSuccess) { transExchnageObj.List.AddRange(responseObj.Result); } else { transExchnageObj.List.AddRange(responseObj.Result); isResponseValid = false; inValidResponseTxt = responseObj.Message.ToString(); } } if (editItemList.Count > 0) { responseObj = UpdateItemInDB(new EditRow() { TableName = tableName, SchemaType = schemaType, IdentityColumnName = identityColumn.ColumnName, dynamicListItems = editItemList, TableSchemaList = schema }); if (responseObj.IsResponseSuccess) { transExchnageObj.List.AddRange(responseObj.Result); } else { transExchnageObj.List.AddRange(responseObj.Result); inValidResponseTxt = responseObj.Message.ToString(); isResponseValid = false; } } } else { return(new Response() { IsResponseSuccess = false, Message = "There is no Identity column. Cannot proccess the action" }); } return(new Response() { IsResponseSuccess = isResponseValid, Message = inValidResponseTxt, TransExchange = transExchnageObj }); } catch (Exception ex) { return(new Response() { IsResponseSuccess = false, Message = ex.Message }); } }