public async Task <string> Insert(ListCityLanguage valCity) { string vResult = "4"; try { City vUserExist = SelectUserPortalByName(valCity.ListCity.FirstOrDefault().Name); if (vUserExist != null) { vResult = "5"; } else if (vUserExist == null) { string vUrl = await UploadAzureHelper.UploadFilesToBlobStorageContainer(valCity.ListCity.FirstOrDefault().Photo?.NameFile, valCity.ListCity.FirstOrDefault().Photo?.FileData); if (vUrl != null) { SQLToolsLibrary vSqlTools = new SQLToolsLibrary(); Guid IdCity = Guid.NewGuid(); List <SqlParameter> vParameterList = new List <SqlParameter> { new SqlParameter("@Id", IdCity != Guid.Empty?IdCity:throw new Exception(GlobalValues.vTextExceptionParameterNull)), new SqlParameter("@Name", !string.IsNullOrEmpty(valCity.ListCity.FirstOrDefault().Name)?valCity.ListCity.FirstOrDefault().Name:throw new Exception(GlobalValues.vTextExceptionParameterNull)), new SqlParameter("@Icon", !string.IsNullOrEmpty(valCity.ListCity.FirstOrDefault().Icon)?valCity.ListCity.FirstOrDefault().Icon:throw new Exception(GlobalValues.vTextExceptionParameterNull)), new SqlParameter("@Temperature", valCity.ListCity.FirstOrDefault().Temperature != int.MinValue?valCity.ListCity.FirstOrDefault().Temperature:throw new Exception(GlobalValues.vTextExceptionParameterNull)), new SqlParameter("@Altitude", valCity.ListCity.FirstOrDefault().Altitude != int.MinValue?valCity.ListCity.FirstOrDefault().Altitude:throw new Exception(GlobalValues.vTextExceptionParameterNull)), new SqlParameter("@Population", valCity.ListCity.FirstOrDefault().Population != int.MinValue?valCity.ListCity.FirstOrDefault().Population:throw new Exception(GlobalValues.vTextExceptionParameterNull)), new SqlParameter("@UrlPhoto", !string.IsNullOrEmpty(vUrl) ? vUrl : throw new Exception(GlobalValues.vTextExceptionParameterNull)), new SqlParameter("@Position", valCity.ListCity.FirstOrDefault().Position != int.MinValue?valCity.ListCity.FirstOrDefault().Position:0), new SqlParameter("@State", valCity.ListCity.FirstOrDefault().State), new SqlParameter("@UserCreate", !string.IsNullOrEmpty(valCity.ListCity.FirstOrDefault().UserCreate) ? valCity.ListCity.FirstOrDefault().UserCreate : throw new Exception(GlobalValues.vTextExceptionParameterNull)), new SqlParameter("@DateCreate", valCity.ListCity.FirstOrDefault().DateCreate != DateTime.MinValue ? valCity.ListCity.FirstOrDefault().DateCreate:DateTime.Now) }; bool vResponseCityLanguage = InsertarListaCityLanguage(valCity.ListCity, IdCity); bool vResponseCity = vSqlTools.ExecuteIUWithStoreProcedure(vParameterList, "sp_Insert_City", vConnection); if (vResponseCity) { if (vResponseCityLanguage) { return(vResult = "1"); } return(vResult = "2"); } } } } catch (Exception vEx) { string vMessage = vEx.Message; return(vResult = "3"); } return(vResult); }
public async Task <IHttpActionResult> Post([FromBody] ListCityLanguage valCity) { string vResult = "4"; ICityData vCityData = new CityData(); try { vResult = await vCityData.Insert(valCity); if (vResult == "1" && !string.IsNullOrEmpty(vResult)) { return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, new { code = HttpStatusCode.OK, Message = Messages.vOkInserted, Result = vResult }))); } } catch (Exception vEx) { string vMessage = vEx.Message; return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, new { code = HttpStatusCode.InternalServerError, Message = Messages.vInternalServerError, Result = vResult }))); } return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotAcceptable, new { code = HttpStatusCode.NotAcceptable, Message = Messages.vNotInserted, Result = vResult }))); }