public async Task <ApiResult <bool> > UpdateUserAddress(UserAddressRequestViewModel userAddress, int userId) { try { SqlParameter AddressId = new SqlParameter("@AddressId", System.Data.SqlDbType.Int) { Value = userAddress.AddressId.HasValue ? userAddress.AddressId.Value : (object)DBNull.Value }; SqlParameter Userid = new SqlParameter("@Userid", System.Data.SqlDbType.Int) { Value = userId > 0 ? userId : (object)DBNull.Value }; SqlParameter Address2 = new SqlParameter("@Address2", System.Data.SqlDbType.VarChar) { Value = userAddress.Address2 }; SqlParameter LandMark = new SqlParameter("@LandMark", System.Data.SqlDbType.VarChar) { Value = userAddress.LandMark ?? (object)DBNull.Value }; int result = await _context.Database.ExecuteSqlCommandAsync("usp_UpdateUserAddress {0},{1},{2},{3}", AddressId, Userid, Address2, LandMark); /// if (result >0) return(new ApiResult <bool>(new ApiResultCode(ApiResultType.Success), true)); // return new ApiResult<bool>(new ApiResultCode(ApiResultType.Success), true); } catch (Exception ex) { ErrorTrace.Logger(LogArea.ApplicationTier, ex); return(new ApiResult <bool>(new ApiResultCode(ApiResultType.Error), false)); } }
public async Task <ApiResult <bool> > SaveUserAddress(UserAddressRequestViewModel userAddress, int userId) { try { userAddress.IsDefaultDeliveryLocation = true; SqlParameter AddressId = new SqlParameter("@AddressId", System.Data.SqlDbType.Int) { Value = userAddress.AddressId.HasValue ? userAddress.AddressId.Value : (object)DBNull.Value }; SqlParameter Userid = new SqlParameter("@Userid", System.Data.SqlDbType.Int) { Value = userId > 0 ? userId : (object)DBNull.Value }; SqlParameter Longitude = new SqlParameter("@Longitude", System.Data.SqlDbType.Decimal) { Value = userAddress.Longitude }; SqlParameter Latitude = new SqlParameter("@Latitude", System.Data.SqlDbType.Decimal) { Value = userAddress.Latitude }; SqlParameter Address1 = new SqlParameter("@Address1", System.Data.SqlDbType.VarChar) { Value = userAddress.Address1 ?? (object)DBNull.Value }; SqlParameter Address2 = new SqlParameter("@Address2", System.Data.SqlDbType.VarChar) { Value = userAddress.Address2 ?? (object)DBNull.Value }; SqlParameter LandMark = new SqlParameter("@LandMark", System.Data.SqlDbType.VarChar) { Value = userAddress.LandMark ?? (object)DBNull.Value }; SqlParameter AddressTypeId = new SqlParameter("@AddressTypeId", System.Data.SqlDbType.Int) { Value = userAddress.AddressTypeId }; SqlParameter IsDefaultDeliveryLocation = new SqlParameter("@IsDefaultDeliveryLocation", System.Data.SqlDbType.Bit) { Value = userAddress.IsDefaultDeliveryLocation }; int result = await _context.Database.ExecuteSqlCommandAsync("usp_SaveUserAddress {0},{1},{2},{3},{4},{5},{6},{7},{8}", AddressId, Userid, Longitude, Latitude, Address1, Address2, LandMark, AddressTypeId, IsDefaultDeliveryLocation); if (result > 0) { return(new ApiResult <bool>(new ApiResultCode(ApiResultType.Success), true)); } } catch (Exception ex) { ErrorTrace.Logger(LogArea.ApplicationTier, ex); } return(new ApiResult <bool>(new ApiResultCode(ApiResultType.Success), false)); }
public async Task <IActionResult> Post([FromForm] UserAddressRequestViewModel value) { int?userId = 0; var struserId = this.User.FindFirstValue(ClaimTypes.Name); if (!string.IsNullOrWhiteSpace(struserId)) { userId = Convert.ToInt32(struserId); } var response = new ListResponse <UserAddressResponseViewModel>(); try { var result = new ApiResult <bool>(); if (value.AddressId != null && value.AddressId > 0) { result = await _unit.IUserAddress.UpdateUserAddress(userAddress : value, userId : userId.Value); response.Data = (await _unit.IUserAddress.UserAddress(userId: userId.Value, addressId: value.AddressId)).UserObject; response.Message = "Success"; response.Status = true; return(response.ToHttpResponse()); } else { result = await _unit.IUserAddress.SaveUserAddress(userAddress : value, userId : userId.Value); if (result.HasSuccess) { response.Data = null; response.Message = "Success"; response.Status = true; } else { response.Data = null; response.Message = "Error"; response.Status = false; } } } catch (Exception ex) { response.Status = false; response.Message = "There was an internal error, please contact to technical support."; ErrorTrace.Logger(LogArea.ApplicationTier, ex); } return(response.ToHttpResponse()); }